GIMP3-ML
DESKTOP-F04AGRR\Kritik Soman 3 years ago
parent a286f1bace
commit 3c9904ae82

@ -1,111 +1,29 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "0f03c378",
"metadata": {},
"outputs": [],
"source": [
"!git clone https://github.com/kritiksoman/GIMP-ML.git\n",
"%cd GIMP-ML\n",
"# !git checkout GIMP3-ML\n",
"# !git checkout 4a9ce5819fc29d117fecde47af6617d0307beb3c\n",
"!git checkout --track origin/GIMP3-ML\n",
"# !git pull \n",
"%cd ..\n",
"!pip install GIMP-ML/.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dca94166",
"cell_type": "markdown",
"id": "67698d1a",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Script will download weights and create gimp_ml_config.pkl, and print path to be added to GIMP Preferences.\n",
"\"\"\"\n",
"import os\n",
"import sys\n",
"import pickle\n",
"import csv\n",
"import hashlib\n",
"import gdown\n",
"\n",
"\n",
"def setup_python_weights(install_location=None):\n",
" if not install_location:\n",
" install_location = os.path.join(os.path.expanduser(\"~\"), \"GIMP-ML\")\n",
" if not os.path.isdir(install_location):\n",
" os.mkdir(install_location)\n",
" python_string = \"python\"\n",
" if os.name == 'nt': # windows\n",
" python_string += \".exe\"\n",
" python_path = os.path.join(os.path.dirname(sys.executable), python_string)\n",
" weight_path = os.path.join(install_location, \"weights\")\n",
" if not os.path.isdir(weight_path):\n",
" os.mkdir(weight_path)\n",
"\n",
" step = 1\n",
" print(\"\\n##########\")\n",
" if os.name == 'nt': # windows\n",
" print(\"{}>> Automatic downloading of weights not supported on Windows.\".format(step))\n",
" step += 1\n",
" print(\"{}>> Please downloads weights folder from: \\n\"\n",
" \"https://drive.google.com/drive/folders/10IiBO4fuMiGQ-spBStnObbk9R-pGp6u8?usp=sharing\".format(step))\n",
" print(\"and place in: \" + weight_path)\n",
" step += 1\n",
" else: # linux\n",
" file_path = os.path.dirname(os.path.realpath(__file__))\n",
" with open(os.path.join(file_path, 'model_info.csv')) as csv_file:\n",
" csv_reader = csv.reader(csv_file, delimiter=',')\n",
" headings = next(csv_reader)\n",
" for row in csv_reader:\n",
" model_path, file_id = os.path.join(*row[0].split(\"/\")), row[1]\n",
" file_size, model_file_name, md5sum = float(row[2]), row[3], row[4]\n",
" if not os.path.isdir(os.path.join(weight_path, model_path)):\n",
" os.makedirs(os.path.join(weight_path, model_path))\n",
" destination = os.path.join(os.path.join(weight_path, model_path), model_file_name)\n",
" if os.path.isfile(destination):\n",
" md5_hash = hashlib.md5()\n",
" a_file = open(destination, \"rb\")\n",
" content = a_file.read()\n",
" md5_hash.update(content)\n",
" digest = md5_hash.hexdigest()\n",
" a_file.close()\n",
" if not os.path.isfile(destination) or (digest and digest != md5sum):\n",
" try:\n",
" gimp.progress_init(\"Downloading \" + model_path + \"(~\" + str(file_size) + \"MB)...\")\n",
" except:\n",
" print(\"\\nDownloading \" + model_path + \"(~\" + str(file_size) + \"MB)...\")\n",
" url = 'https://drive.google.com/uc?id={0}'.format(file_id)\n",
" try:\n",
" gdown.cached_download(url, destination, md5=md5sum)\n",
" except:\n",
" try:\n",
" gdown.download(url, destination, quiet=False)\n",
" except:\n",
" print(\"Failed to download !\")\n",
" # plugin_loc = os.path.dirname(os.path.realpath(__file__))\n",
" import gimpml\n",
" plugin_loc = os.path.dirname(gimpml.__file__)\n",
" with open(os.path.join(plugin_loc, 'tools', 'gimp_ml_config.pkl'), 'wb') as file:\n",
" pickle.dump({\"python_path\": python_path, \"weight_path\": weight_path}, file)\n",
"\n",
" print(\"{}>> Please add this path to Preferences --> Plug-ins in GIMP : \".format(step),\n",
" os.path.join(plugin_loc, \"plugins\"))\n",
" print(\"##########\\n\")"
"# Setup\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3536a387",
"id": "aa70db70",
"metadata": {},
"outputs": [],
"source": [
"# Run this cell for google colab otherwise setup using GIMP-ML/install.bat\n",
"# In Colab, choose runtime with GPU acceleration\n",
"!git clone https://github.com/kritiksoman/GIMP-ML.git\n",
"%cd GIMP-ML\n",
"!git checkout --track origin/GIMP3-ML\n",
"%cd ..\n",
"!pip install GIMP-ML/.\n",
"import gimpml\n",
"gimpml.setup_python_weights()\n",
"%cd /content/GIMP-ML/testscases"
]
},

@ -1,111 +1,29 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "0f03c378",
"metadata": {},
"outputs": [],
"source": [
"!git clone https://github.com/kritiksoman/GIMP-ML.git\n",
"%cd GIMP-ML\n",
"# !git checkout GIMP3-ML\n",
"# !git checkout 4a9ce5819fc29d117fecde47af6617d0307beb3c\n",
"!git checkout --track origin/GIMP3-ML\n",
"# !git pull \n",
"%cd ..\n",
"!pip install GIMP-ML/.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dca94166",
"cell_type": "markdown",
"id": "67698d1a",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Script will download weights and create gimp_ml_config.pkl, and print path to be added to GIMP Preferences.\n",
"\"\"\"\n",
"import os\n",
"import sys\n",
"import pickle\n",
"import csv\n",
"import hashlib\n",
"import gdown\n",
"\n",
"\n",
"def setup_python_weights(install_location=None):\n",
" if not install_location:\n",
" install_location = os.path.join(os.path.expanduser(\"~\"), \"GIMP-ML\")\n",
" if not os.path.isdir(install_location):\n",
" os.mkdir(install_location)\n",
" python_string = \"python\"\n",
" if os.name == 'nt': # windows\n",
" python_string += \".exe\"\n",
" python_path = os.path.join(os.path.dirname(sys.executable), python_string)\n",
" weight_path = os.path.join(install_location, \"weights\")\n",
" if not os.path.isdir(weight_path):\n",
" os.mkdir(weight_path)\n",
"\n",
" step = 1\n",
" print(\"\\n##########\")\n",
" if os.name == 'nt': # windows\n",
" print(\"{}>> Automatic downloading of weights not supported on Windows.\".format(step))\n",
" step += 1\n",
" print(\"{}>> Please downloads weights folder from: \\n\"\n",
" \"https://drive.google.com/drive/folders/10IiBO4fuMiGQ-spBStnObbk9R-pGp6u8?usp=sharing\".format(step))\n",
" print(\"and place in: \" + weight_path)\n",
" step += 1\n",
" else: # linux\n",
" file_path = os.path.dirname(os.path.realpath(__file__))\n",
" with open(os.path.join(file_path, 'model_info.csv')) as csv_file:\n",
" csv_reader = csv.reader(csv_file, delimiter=',')\n",
" headings = next(csv_reader)\n",
" for row in csv_reader:\n",
" model_path, file_id = os.path.join(*row[0].split(\"/\")), row[1]\n",
" file_size, model_file_name, md5sum = float(row[2]), row[3], row[4]\n",
" if not os.path.isdir(os.path.join(weight_path, model_path)):\n",
" os.makedirs(os.path.join(weight_path, model_path))\n",
" destination = os.path.join(os.path.join(weight_path, model_path), model_file_name)\n",
" if os.path.isfile(destination):\n",
" md5_hash = hashlib.md5()\n",
" a_file = open(destination, \"rb\")\n",
" content = a_file.read()\n",
" md5_hash.update(content)\n",
" digest = md5_hash.hexdigest()\n",
" a_file.close()\n",
" if not os.path.isfile(destination) or (digest and digest != md5sum):\n",
" try:\n",
" gimp.progress_init(\"Downloading \" + model_path + \"(~\" + str(file_size) + \"MB)...\")\n",
" except:\n",
" print(\"\\nDownloading \" + model_path + \"(~\" + str(file_size) + \"MB)...\")\n",
" url = 'https://drive.google.com/uc?id={0}'.format(file_id)\n",
" try:\n",
" gdown.cached_download(url, destination, md5=md5sum)\n",
" except:\n",
" try:\n",
" gdown.download(url, destination, quiet=False)\n",
" except:\n",
" print(\"Failed to download !\")\n",
" # plugin_loc = os.path.dirname(os.path.realpath(__file__))\n",
" import gimpml\n",
" plugin_loc = os.path.dirname(gimpml.__file__)\n",
" with open(os.path.join(plugin_loc, 'tools', 'gimp_ml_config.pkl'), 'wb') as file:\n",
" pickle.dump({\"python_path\": python_path, \"weight_path\": weight_path}, file)\n",
"\n",
" print(\"{}>> Please add this path to Preferences --> Plug-ins in GIMP : \".format(step),\n",
" os.path.join(plugin_loc, \"plugins\"))\n",
" print(\"##########\\n\")"
"# Setup\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3536a387",
"id": "aa70db70",
"metadata": {},
"outputs": [],
"source": [
"# Run this cell for google colab otherwise setup using GIMP-ML/install.bat\n",
"# In Colab, choose runtime with GPU acceleration\n",
"!git clone https://github.com/kritiksoman/GIMP-ML.git\n",
"%cd GIMP-ML\n",
"!git checkout --track origin/GIMP3-ML\n",
"%cd ..\n",
"!pip install GIMP-ML/.\n",
"import gimpml\n",
"gimpml.setup_python_weights()\n",
"%cd /content/GIMP-ML/testscases"
]
},

Loading…
Cancel
Save