Skip to content
/ pytorch_template Public template

Pytorch Implementation example of Image Classification with flowers recognition dataset

License

Notifications You must be signed in to change notification settings

yiskw713/pytorch_template

Repository files navigation

Pytorch Template

status-badge

project for pytorch implementation example of image classification

Requirements

Please run poetry install to install the necessary packages.

You can also setup the environment using docker and docker-compose.

Dataset

Flowers Recognition Dataset Download the dataset from HERE

Directory Structure

.
├── docs/
├── LICENSE
├── README.md
├── dataset/
│   └── flowers/
├── pyproject.toml
├── .gitignore
├── .gitattributes
├── .pre-commit-config.yaml
├── poetry.lock
├── docker-compose.yaml
├── Dockerfile
├── tests/
└── src/
    ├── csv
    ├── libs/
    ├── utils
    ├── notebook/
    ├── result/
    ├── scripts/
    │   └── experiment.sh
    ├── train.py
    └── evaluate.py

Features

  • configuration class using dataclasses.dataclass (libs/config.py)

    • type check.
    • detection of unnecessary / extra parameters in a specified configuration.
    • dataclass is an immutable object, which prevents the setting from being changed by mistake.
  • automatically generating configuration files (utils/make_configs.py)

    • e.g.) run this command
    python utils/make_configs.py --model resnet18 resnet30 resnet50 --learning_rate 0.001 0.0001 --dataset_name flower

    then you can get all of the combinations with model and learning_rate (total 6 config files), while the other parameters are set by default as described in libs/config.py.

    You can choose which data you use in experiment by specifying dataset_name. The lists of data for training, validation and testing are saved as csv files. You can see the paths to them in libs/dataset_csv.py and get them corresponding to dataset_name. If you want to use another dataset, please add csv files and the paths in DATASET_CSVS in libs/dataset_csv.py.

    You can also set tuple object parameters in configs like the below.

    python utils/make_configs.py --model resnet18 --topk 1 3 --topk 1 3 5

    By running this, you can get two configurations, in one of which topk parameter is (1, 3) and in the other topk parameter is (1, 3, 5).

  • running all the experiments by running shell scripts (scripts/experiment.sh)

  • support type annotation (typing)

  • code formatting with black, isort and flake8

  • visualize model for debug using hiddenlayer (src/utils/visualize_model.py)

Experiment

Please see scripts/experiment.sh for the detail. You can set configurations and run all the experiments by the below command.

sh scripts/experiment.sh

Setup dependencies

If you use local environment, then run

poetry install

If you use docker, then run

docker-compose up -d --build
docker-compose run mlserver bash

training

python train.py ./result/xxxx/config.yaml

evaluation

python evaluate.py ./result/xxxx/config.yaml validation
python evaluate.py ./result/xxxx/config.yaml test

Model visualization

python utils/visualize_model.py MODEL_NAME

Formatting

  • black
  • flake8
  • isort

TODO

  • pytorch implementation of image classification
  • configuration class using dataclasses.dataclass
  • auto generation of config yaml files
  • shell script to run all the experiment
  • support typing (type annotation)
  • test code (run testing with pre-commit check)
  • mypy (pre-commit check)
  • formatting (pre-commit isort, black and flake8)
  • calculate cyclomatic complexity / expression complexity / cognitive complexity (flake8 extension)
  • CI for testing using GitHub Actions
  • visualization of models
  • add Dockerfile and docker-compose.yaml

License

This repository is released under the MIT License

About

Pytorch Implementation example of Image Classification with flowers recognition dataset

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published