{"id":27195940,"url":"https://github.com/moisestech/stylegan2-training-notes","last_synced_at":"2025-10-08T08:27:32.620Z","repository":{"id":68218308,"uuid":"269484435","full_name":"moisestech/stylegan2-training-notes","owner":"moisestech","description":"StyleGAN2 Training Notes","archived":false,"fork":false,"pushed_at":"2020-06-07T14:47:03.000Z","size":1846,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T19:51:41.738Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moisestech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-04T23:13:36.000Z","updated_at":"2021-04-16T10:40:05.000Z","dependencies_parsed_at":"2023-02-23T04:15:19.531Z","dependency_job_id":null,"html_url":"https://github.com/moisestech/stylegan2-training-notes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/moisestech/stylegan2-training-notes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisestech%2Fstylegan2-training-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisestech%2Fstylegan2-training-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisestech%2Fstylegan2-training-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisestech%2Fstylegan2-training-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moisestech","download_url":"https://codeload.github.com/moisestech/stylegan2-training-notes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisestech%2Fstylegan2-training-notes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278912432,"owners_count":26067455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-09T19:48:13.604Z","updated_at":"2025-10-08T08:27:32.612Z","avatar_url":"https://github.com/moisestech.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Training a Non-Square StyleGAN2 model on GCP\n\n**#stylegan2** **#non-square**  **#gcp**\n\nNotes :pencil: based on [Training StyleGAN2 Part 2 Video](www.youtube.com/watch?v=Ij1dqSVR89M) :movie_camera: taught in the [StyleGAN2 DeepDive course]([https://bustbright.square.site/s/shop](https://bustbright.square.site/s/shop)) :books:by [@Derrick Schultz]([https://twitter.com/dvsch](https://twitter.com/dvsch)) and [@Lia Coleman]([https://twitter.com/Lialialiacole](https://twitter.com/Lialialiacole)). The asterisk * on each numbered section will link to the video timecode of the tutorial.\n\n## 1. Start-up Server :gear: [*](https://youtu.be/Ij1dqSVR89M?t=19)\n1. Login into [GCP](console.cloud.google.com)\n2. Click launch on your Compute account. (image?)\n\n**Notes:**\n- Have your dataset ready and uploaded in :file_folder:Google Drive.\n\t-  Vertical :art: Images: 767px by 1200px\n\t- Square :art: Images: 1024px by 1024px\n- Refer to the Github :octocat: repo [skyfkynil/stylegan2](https://github.com/skyflynil/stylegan2)  for detailed directions.\n- For further information refer to the paper Official TensorFlow Implementation with practical improvements :page_facing_up:[http://arxiv.org/abs/1912.04958](http://arxiv.org/abs/1912.04958)\n\n## 2. SSH Login Open in Browser Window :computer: [*](https://youtu.be/Ij1dqSVR89M?t=84)\n-   Click Login through SSH Connect, opening a browser window.\n\n\t- Out of the box doesn’t have static IP (It can be set-up)\n\n## 3. Activate StyleGAN2 library :snake: [*](https://youtu.be/Ij1dqSVR89M?t=121)\n1. In Terminal activate your anaconda environment. \n\t```\n\tconda activate stylegan\n\t```\n\n## 4.  Set-up Dataset Folder :file_folder: [*](https://youtu.be/Ij1dqSVR89M?t=176)\n1. Move into the skyflynil folder and go into the folder *datasets*\n2. Place all TFRecords in the datasets folder.\n3. Create raw_datasets folder\n\t```\n\tmkdir raw_datasets\n\t```\n\t-   (Why? To differentiate raw images from tfrecord folders)\n4. Go inside your new folder\n\t```\n\tcd into raw_datasets\n\t``` \n## 5. Upload Dataset images in GCP :arrow_up: [*](https://youtu.be/Ij1dqSVR89M?t=218)\n1. Use [GDown](https://pypi.org/project/gdown/)\n2. Pass the ID to a file\n3. On GDrive, toggle Share linking on and copy the ID\n\t```\n\tgdown --id id-ofyour-gdrive-zip-file\n\t```\t\n\t-   GServer to GServer is really fast\n\n## 6. Unzip :closed_lock_with_key: [*](https://youtu.be/Ij1dqSVR89M?t=311) \n1.  Unzip your gdown file\n\t```\n\tunzip dataset-name.zip\n\t```\n2.   Clean up your raw_dataset folder by removing the zip file\n```\nrm dataset-name.zip \n```\n3. Go back to the main styleGAN2 folder\n\t```\n\t..//\n\t```\n\n    \n## 7. Create our TFRecords files :crystal_ball: [*](https://youtu.be/Ij1dqSVR89M?t=363)\n1.  Create TFRecords from your image files, rather than training from raw-images (optimization)\n\t```\n\t!python dataset_tool.py create_from_images_raw --res_log2=8 ./dataset/dataset_name ./raw_datasets/dataset-name/\n\t```\n\t  -   you should see raw-dataset TFRecords file\n\t  - (base) stylegan-ver: 1\n\n**Notes**\t\n- **Detailed instruction for training your [stylegan2 skyflynil notes](https://github.com/skyflynil/stylegan2)**\n\n\t-  Instead of image size of 2^n * 2^n, now you can process your image size as of (min_h x 2^n) X (min_w * 2^n) naturally. For example, 640x384, min_h = 5, min_w =3, n=7. Please make sure all your raw images are preprocessed to the exact same size. To reduce the training set size, JPEG format is preferred.\n\n\t- For image size 1280x768 (hxw), you may choose (min_h, min_w, res_log2) as (10, 6, 7) or (5, 3, 8) , the latter setup is preferred due to deeper and smaller network, change res_log2 argument for dataset creation and training accordingly.\n\n- For information on installing your anaconda environment check out the video [StyleGAN2 installation on GCP]([https://www.youtube.com/watch?v=59hpiFMjhpY](https://www.youtube.com/watch?v=59hpiFMjhpY)) :movie_camera:\n- Documentation link to [listing out your anaconda environments]([https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments)) on Terminal\n\n## 8. Upload \u0026 Transfer Learn from a new model :orange_book: [*](https://youtu.be/Ij1dqSVR89M?t=603)\n- If your dataset are :art: images with dimensions 1200px by 768px, or 768px by 1200px (non-square) you must transfer learn from a model trained on those dimensions.\n- The model that is default set in transfer learning is 1024px by 1024ox.\n- You can't transfer learn if the size of your model and the size of your dataset don't match.\n\n1. Setup Results Folder :file_folder: to Ignore (\"rename\") :no_entry_sign: Square Model [*](https://youtu.be/Ij1dqSVR89M?t=660)\n```\nmv results/00000-pretrained/network-snapshot-1000.pkl results/00000-pretrained/network-snapshot-1000.pkl-ignore\n```\n2. Get the sharable link to your non-square model pre-trained .pkl file on Google Drive and Gdown the file into the results folder.\n```\ngdown --id id-ofyour-pkl-file\n``` \n\n## 9. Train Model :gear: [*](https://youtu.be/Ij1dqSVR89M?t=888)\n\n```\n!python run_training.py --num-gpus=1 --data-dir=./dataset --config=config-f --dataset=your_dataset_name --mirror-augment=true --metric=none --total-kimg=20000 --min-h=5 --min-w=3 --res-log2=8 --result-dir=\"/content/drive/My Drive/stylegan2/results\"\n```\n**Notes**\n\n - *data-dir* should always point to the parent of your parent directory of your TFRecords folder.\n - *config* use config-e (512px) or config-f (1024px), it depends on the size of the image your are outputting to.\n - *dataset* input the name of your dataset folder :file_folder:\n - *total kimages* 20000\n -  *res-log2* means it is a power of 2\n\t - so the model will multiply log2-8 by min-width=5 and min-height=2\n\t - which gives us our 1280px by 768px training dimensions. \n\t\t - width: 2^6*2  = 768\n\t\t - height=2^8*5  1200\n - This repo recommends that if you are doing 128 it recommends you use 7\n\t - Because that 8th channel although it makes the network a little bit deeper it makes it smaller overall\n - :warning: You can’t do a 16:9 or 720p aspect ratios.\n\n## 10. Check on Your Training :eyes: [*](https://youtu.be/Ij1dqSVR89M?t=1130)\n**Notes:**\n1. We are ready to start training, it will display that is is training from your last :cactus: .pkl file\n\n![enter image description here](https://github.com//Moises404/stylegan2-training-notes/blob/master/Training_NonSquareModel.png?raw=true)\n\t\t\n- Its might be a bit slower the first time on the same machine because it is caching some files.\n- *Data shape* = [3, 1280, 768] :triangular_ruler:\n- *Dynamic range* = [0, 255] :traffic_light:\n\t- Range 0-255 256 the size that we can work with loading networks\n2. Custom Cuda commands compile\n\t- (2- 5 minute wait) :clock4:\n\t- Outputting the architecture\n\n![enter image description here](https://raw.githubusercontent.com/Moises404/stylegan2-training-notes/master/Training_NonSquareModel_InProcess_2.png)\n\n![enter image description here](https://raw.githubusercontent.com/Moises404/stylegan2-training-notes/master/Training_NonSquareModel_Confirmed_Training.png)\n3. To confirm :white_check_mark:, terminal should output process above :point_up_2:\n* Building *Tensorflow graph*\n* Training for *20 kimages*\n* You will produce an initial :cactus: .pkl file from its current status.\n* Outputting pickling up from the same image\n* Size of the *mini-batches*\n* Size of *gpumem* is how much memory the training is using. (underestimates)\n* *Warning:* :warning: might throw error if the datasets TFRecords file is not the right shape.\n\n## 11. Create Training Subprocess :link: [*](https://youtu.be/Ij1dqSVR89M?t=1475)\n- GCP terminal when closed, also terminates the training process.\n1. [Nohup](https://en.wikipedia.org/wiki/Nohup) re-running the script using *Nohup* is a background process in the GPU that will allow us to close the browser window and continue the training process.\n\n![enter image description here](https://github.com/Moises404/stylegan2-training-notes/blob/master/Training_nohup_start.png?raw=true)\n- Other solutions: Install gnu, gmux\n2. Now we will check *nohup.out* to asses wether this is working as a background process.\n```\nNvdia-smi\n```\n![enter image description here](https://github.com/Moises404/stylegan2-training-notes/blob/master/Training-Nvdia-smi.png?raw=true)\n- Cuda version 4.0\n- How much GPU are you using\n- Process ID python 15.7gb\n- This is your command running on the GPU\n```\nKill -9 PID number\n```\n    \n## 13. 1 Day of Training Later.. :sunrise:\n- 24 hours of training later  :clock4:\n1.  In [GCP](console.cloud.google.com) head back to your server into the skyflynil folder :file_folder:\n2. Since *nohup* has made the training run as a subprocess you will have to type the Nvdia-smi command to check that it is running properly\n\n```\nNvdia-smi\n```\n\n3. Terminate the sub-process\n```\nls results\n``` \n\n4. Head inside the results folder which will have the results labeled with your dataset name.\n```\ncd/results/0003-stylegan2-your_dataset_name\n```\n\n-  Training 80k images can start reflecting dataset ok enough.\n- Training up to 500k images gets to a really good point  \n-   Truncation values will vary in displayed results.\n\n\n\n## 14. Download file :arrow_heading_down: nohup.out :bookmark_tabs: [*](https://youtu.be/Ij1dqSVR89M?t=1963)\n1. Download the nohup .out file\n```\nls pwd\n``` \n\n![enter image description here](https://github.com/Moises404/stylegan2-training-notes/blob/master/Training_DownloadFiles2.png?raw=true)\n2. Open in Text Editor and scroll to the bottom\n\n![enter image description here](https://raw.githubusercontent.com/Moises404/stylegan2-training-notes/master/Training_Reading_nohup_files.png)\n\n**Notes:** \n- A *tick* is a certain number of *kimages*, depending on what you set your *mini-batch* too\n- How long does it take to train a tick faster with how quickly it takes\n\nHope these notes help to breakdown the StyleGAN2 video tutorial for reference in the future. :rocket:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoisestech%2Fstylegan2-training-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoisestech%2Fstylegan2-training-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoisestech%2Fstylegan2-training-notes/lists"}