Skip to content

Commit

Permalink
Deleting and updating old code from the colab
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidalnt committed Aug 25, 2024
1 parent 93559da commit db9dd38
Showing 1 changed file with 23 additions and 63 deletions.
86 changes: 23 additions & 63 deletions assets/Applio_NoUI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -310,48 +310,24 @@
"import time\n",
"\n",
"LOGS_FOLDER = \"/content/Applio/logs/\"\n",
"WEIGHTS_FOLDER = LOGS_FOLDER + model_name\n",
"GOOGLE_DRIVE_PATH = \"/content/drive/MyDrive/RVC_Backup\"\n",
"\n",
"\n",
"def import_google_drive_backup():\n",
" print(\"Importing Google Drive backup...\")\n",
" weights_exist = False\n",
" for root, dirs, files in os.walk(GOOGLE_DRIVE_PATH):\n",
" for filename in files:\n",
" filepath = os.path.join(root, filename)\n",
" if os.path.isfile(filepath) and not filepath.startswith(\n",
" os.path.join(GOOGLE_DRIVE_PATH, \"weights\")\n",
" ):\n",
" if os.path.isfile(filepath):\n",
" backup_filepath = os.path.join(\n",
" LOGS_FOLDER, os.path.relpath(filepath, GOOGLE_DRIVE_PATH)\n",
" )\n",
" backup_folderpath = os.path.dirname(backup_filepath)\n",
" if not os.path.exists(backup_folderpath):\n",
" os.makedirs(backup_folderpath)\n",
" print(f\"Created backup folder: {backup_folderpath}\", flush=True)\n",
" shutil.copy2(filepath, backup_filepath) # copy file with metadata\n",
" shutil.copy2(filepath, backup_filepath)\n",
" print(f\"Imported file from Google Drive backup: {filename}\")\n",
" elif filepath.startswith(\n",
" os.path.join(GOOGLE_DRIVE_PATH, \"weights\")\n",
" ) and filename.endswith(\".pth\"):\n",
" weights_exist = True\n",
" weights_filepath = os.path.join(\n",
" WEIGHTS_FOLDER,\n",
" os.path.relpath(\n",
" filepath, os.path.join(GOOGLE_DRIVE_PATH, \"weights\")\n",
" ),\n",
" )\n",
" weights_folderpath = os.path.dirname(weights_filepath)\n",
" if not os.path.exists(weights_folderpath):\n",
" os.makedirs(weights_folderpath)\n",
" print(f\"Created weights folder: {weights_folderpath}\", flush=True)\n",
" shutil.copy2(filepath, weights_filepath) # copy file with metadata\n",
" print(f\"Imported file from weights: {filename}\")\n",
" if weights_exist:\n",
" print(\"Copied weights from Google Drive backup to local weights folder.\")\n",
" else:\n",
" print(\"No weights found in Google Drive backup.\")\n",
" print(\"Google Drive backup import completed.\")\n",
"\n",
"\n",
Expand All @@ -363,31 +339,6 @@
" return hash_md5.hexdigest()\n",
"\n",
"\n",
"def copy_weights_folder_to_drive():\n",
" destination_folder = os.path.join(GOOGLE_DRIVE_PATH, \"weights\")\n",
" try:\n",
" if not os.path.exists(destination_folder):\n",
" os.makedirs(destination_folder)\n",
"\n",
" num_copied = 0\n",
" for filename in os.listdir(WEIGHTS_FOLDER):\n",
" if filename.endswith(\".pth\"):\n",
" source_file = os.path.join(WEIGHTS_FOLDER, filename)\n",
" destination_file = os.path.join(destination_folder, filename)\n",
" if not os.path.exists(destination_file):\n",
" shutil.copy2(source_file, destination_file)\n",
" num_copied += 1\n",
" print(f\"Copied {filename} to Google Drive!\")\n",
"\n",
" if num_copied == 0:\n",
" print(\"No new finished models found for copying.\")\n",
" else:\n",
" print(f\"Finished copying {num_copied} files to Google Drive!\")\n",
"\n",
" except Exception as error:\n",
" print(f\"An error occurred during copying weights to Google Drive: {str(error)}\")\n",
"\n",
"\n",
"if \"autobackups\" not in globals():\n",
" autobackups = False\n",
"\n",
Expand All @@ -411,7 +362,6 @@
" pass\n",
"\n",
" for root, dirs, files in os.walk(LOGS_FOLDER):\n",
" # Excluding \"zips\" directory\n",
" if \"zips\" in dirs:\n",
" dirs.remove(\"zips\")\n",
" if \"mute\" in dirs:\n",
Expand Down Expand Up @@ -482,7 +432,7 @@
" print(\"Autobackup Disabled\")\n",
"else:\n",
" autobackups = True\n",
" print(\"Autobackup Enabled\")\n",
" print(\"Autobackup Enabled\") \n",
"\n",
"total_epoch = 800 # @param {type:\"integer\"}\n",
"batch_size = 15 # @param {type:\"slider\", min:1, max:25, step:0}\n",
Expand Down Expand Up @@ -562,7 +512,7 @@
"# @title Save model\n",
"# @markdown Enter the name of the model and the steps. You can find it in your `/content/Applio/logs` folder.\n",
"%cd /content\n",
"import shutil, os\n",
"import os, shutil, sys\n",
"\n",
"model_name = \"Darwin\" # @param {type:\"string\"}\n",
"model_epoch = 800 # @param {type:\"integer\"}\n",
Expand All @@ -571,14 +521,27 @@
"if os.path.exists(\"/content/zips\"):\n",
" shutil.rmtree(\"/content/zips\")\n",
"print(\"Removed zips.\")\n",
"!mkdir -p /content/zips/{model_name}/\n",
"\n",
"os.makedirs(f\"/content/zips/{model_name}/\", exist_ok=True)\n",
"print(\"Created zips.\")\n",
"if f\"{model_name}.pth\" not in os.listdir(f\"/content/Applio/weights\"):\n",
"\n",
"logs_folder = f\"/content/Applio/logs/{model_name}/\"\n",
"weight_file = None\n",
"if not os.path.exists(logs_folder):\n",
" print(f\"Model folder not found.\")\n",
" sys.exit(\"\")\n",
"\n",
"for filename in os.listdir(logs_folder):\n",
" if filename.startswith(f\"{model_name}_{model_epoch}e\") and filename.endswith(\".pth\"):\n",
" weight_file = filename\n",
" break\n",
"if weight_file is None:\n",
" print(\"There is no weight file with that name\")\n",
" sys.exit(\"\")\n",
"if not save_big_file:\n",
" !cp /content/Applio/logs/{model_name}/added_*.index /content/zips/{model_name}/\n",
" !cp /content/Applio/logs/{model_name}/total_*.npy /content/zips/{model_name}/\n",
" !cp /content/Applio/weights/{model_name}.pth /content/zips/{model_name}/{model_name}{model_epoch}.pth\n",
" !cp {logs_folder}added_*.index /content/zips/{model_name}/\n",
" !cp {logs_folder}total_*.npy /content/zips/{model_name}/\n",
" !cp {logs_folder}{weight_file} /content/zips/{model_name}/\n",
" %cd /content/zips\n",
" !zip -r {model_name}.zip {model_name}\n",
"if save_big_file:\n",
Expand All @@ -599,16 +562,13 @@
" !zip -r {ZIPFILEPATH} {os.path.join(logs_folder, filename)}\n",
" else:\n",
" !zip -r {ZIPFILEPATH} {os.path.join(logs_folder, filename)}\n",
" for filename in os.listdir(\"./weights\"):\n",
" if model_name in filename:\n",
" !zip -r {ZIPFILEPATH} {os.path.join('./weights/', filename)}\n",
"\n",
"!mkdir -p /content/drive/MyDrive/RVC_Backup/\n",
"shutil.move(\n",
" f\"/content/zips/{model_name}.zip\",\n",
" f\"/content/drive/MyDrive/RVC_Backup/{model_name}.zip\",\n",
")\n",
"%cd /content\n",
"%cd /content/Applio\n",
"shutil.rmtree(\"/content/zips\")"
]
},
Expand Down

0 comments on commit db9dd38

Please sign in to comment.