{"id":19736691,"url":"https://github.com/anyesh/stackgan","last_synced_at":"2025-07-08T04:10:25.304Z","repository":{"id":37646824,"uuid":"272594763","full_name":"Anyesh/StackGAN","owner":"Anyesh","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-25T10:58:22.000Z","size":4748,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T19:11:43.466Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","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/Anyesh.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}},"created_at":"2020-06-16T02:51:38.000Z","updated_at":"2020-09-17T02:05:09.000Z","dependencies_parsed_at":"2022-09-04T20:10:48.302Z","dependency_job_id":null,"html_url":"https://github.com/Anyesh/StackGAN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyesh%2FStackGAN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyesh%2FStackGAN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyesh%2FStackGAN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyesh%2FStackGAN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Anyesh","download_url":"https://codeload.github.com/Anyesh/StackGAN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241062609,"owners_count":19902924,"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","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":"2024-11-12T01:08:08.272Z","updated_at":"2025-02-27T21:45:12.334Z","avatar_url":"https://github.com/Anyesh.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pytorch Deep Learning Template\n### A clean and simple template to kick start your next dl project 🚀🚀\n*Francesco Saverio Zuppichini*\n\nIn this article, we present you a deep learning template based on Pytorch. This template aims to make it easier for you to start a new deep learning computer vision project with PyTorch. The main features are:\n\n- modularity: we split each logic piece into a different python submodule\n- data-augmentation: we included [imgaug](https://imgaug.readthedocs.io/en/latest/)\n- ready to go: by using [poutyne](https://pypi.org/project/Poutyne/) a Keras-like framework you don't have to write any train loop.\n- [torchsummary](https://github.com/sksq96/pytorch-summary) to show a summary of your models\n- reduce the learning rate on a plateau\n- auto-saving the best model\n- experiment tracking with [comet](https://www.comet.ml/)\n- logging using python [logging](https://docs.python.org/3/library/logging.html) module\n- a playground notebook to quick test/play around\n## Installation\nClone the repo and go inside it. Then, run:\n\n```\npip install -r requirements.txt\n```\n\n### Motivation\nLet's face it, usually data scientists are not software engineers and they usually end up with spaghetti code, most of the time on a big unusable Jupiter-notebook. With this repo, you have proposed a clean example of how your code should be split and modularized to make scalability and sharability possible. In this example, we will try to classify Darth Vader and Luke Skywalker. We have 100 images per class gathered using google images. The dataset is [here](https://drive.google.com/open?id=1LyHJxUVjOgDIgGJL4MnDhA10xjejWuw7). You just have to exact it in this folder and run main.py. We are fine-tuning resnet18 and it should be able to reach \u003e 90% accuracy in 5/10 epochs.\n## Structure\nThe template is inside `./template`.\n```\n.\n├── callbacks // here you can create your custom callbacks\n├── checkpoint // were we store the trained models\n├── data // here we define our dataset\n│ └── transformation // custom transformation, e.g. resize and data augmentation\n├── dataset // the data\n│ ├── train\n│ └── val\n├── logger.py // were we define our logger\n├── losses // custom losses\n├── main.py\n├── models // here we create our models\n│ ├── MyCNN.py\n│ ├── resnet.py\n│ └── utils.py\n├── playground.ipynb // a notebook that can be used to fast experiment with things\n├── Project.py // a class that represents the project structure\n├── README.md\n├── requirements.txt\n├── test // you should always perform some basic testing\n│ └── test_myDataset.py\n└── utils.py // utilities functions\n```\n**We strongly encourage to play around with the template**\n### Keep your structure clean and concise\nEvery deep learning project has at least three mains steps:\n- data gathering/processing\n- modeling\n- training/evaluating\n## Project\nOne good idea is to store all the paths at an interesting location, e.g. the dataset folder, in a shared class that be accessed by anyone in the folder. You should never hardcode any paths and always define them once and import them. So, if you later change your structure you will only have to modify one file.\nIf we have a look at `Project.py` we can see how we defined the `data_dir` and the `checkpoint_dir` once for all. We are using the 'new' [Path](https://docs.python.org/3/library/pathlib.html) APIs that support different OS out of the box, and also make it easier to join and concatenate paths.\n![alt](https://raw.githubusercontent.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/develop/images/Project.png)\nFor example, if we want to know the data location we can :\n```python3\nfrom Project import project\nprint(projct.data_dir) # /foo/baa/…/dataset\n```\n## Data\nIn the `data` package you can define your own Dataset, as always by subclassing `torch.data.utils.Dataset`, exposing transformations and utilities to work with your data.\nIn our example, we directly used `ImageDataset` from `torchvision` but we included a skeleton for a custom `Dataset` in `/data/MyDataset`\n### Transformation\nYou usually have to do some preprocessing on the data, e.g. resize the images and apply data augmentation. All your transformation should go inside `.data.trasformation`. In our template, we included a wrapper for\n[imgaug](https://imgaug.readthedocs.io/en/latest/)\n![alt](https://raw.githubusercontent.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/develop/images/transformation.png)\n### Dataloaders\nAs you know, you have to create a `Dataloader` to feed your data into the model. In the `data.__init__.py` file we expose a very simple function `get_dataloaders` to automatically configure the *train, val and test* data loaders using few parameters\n![alt](https://raw.githubusercontent.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/develop/images/data.png)\n## Losses\nSometimes you may need to define your custom losses, you can include them in the `./losses` package. For example\n![alt](https://raw.githubusercontent.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/develop/images/losses.png)\n## Logging \nWe included python [logging](https://docs.python.org/3/library/logging.html) module. You can import and use it by:\n\n```python\nfrom logger import logger\nlogger.info('print() is for noobs')\n```\n\n## Models\nAll your models go inside `models`, in our case, we have a very basic cnn and we override the `resnet18` function to provide a frozen model to finetune.\n\n![alt](https://github.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/blob/develop/images/resnet.png?raw=true)\n## Train/Evaluation\nIn our case we kept things simple, all the training and evaluation logic is inside `.main.py` where we used [poutyne](https://pypi.org/project/Poutyne/) as the main library. We already defined a useful list of callbacks:\n- learning rate scheduler\n- auto-save of the best model\n- early stopping\nUsually, this is all you need!\n![alt](https://github.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/blob/develop/images/main.png?raw=true)\n### Callbacks \nYou may need to create custom callbacks, with [poutyne](https://pypi.org/project/Poutyne/) is very easy since it support Keras-like API. You custom callbacks should go inside `./callbacks`. For example, we have created one to update Comet every epoch.\n![alt](https://github.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/blob/develop/images/CometCallback.png?raw=true)\n\n### Track your experiment\nWe are using [comet](https://www.comet.ml/) to automatically track our models' results. This is what comet's board looks like after a few models run.\n![alt](https://github.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/blob/develop/images/comet.jpg?raw=true)\nRunning `main.py` produces the following output:\n![alt](https://github.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/blob/develop/images/output.jpg?raw=true)\n## Utils\nWe also created different utilities function to plot booth dataset and dataloader. They are in `utils.py`. For example, calling `show_dl` on our train and val dataset produces the following outputs.\n![alt](https://github.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/blob/develop/images/Figure_1.png?raw=true)\n![alt](https://github.com/FrancescoSaverioZuppichini/PyTorch-Deep-Learning-Skeletron/blob/develop/images/Figure_2.png?raw=true)\nAs you can see data-augmentation is correctly applied on the train set\n## Conclusions\nI hope you found some useful information and hopefully it this template will help you on your next amazing project :)\n\nLet me know if you have some ideas/suggestions to improve it.\n\nThank you for reading\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanyesh%2Fstackgan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanyesh%2Fstackgan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanyesh%2Fstackgan/lists"}