pretrain-finetuning

COMP3340 Group 10 - Pretrain-finetuning part implemented by Alex.

https://github.com/comp3340-2024-gp11/pretrain-finetuning

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.9%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

COMP3340 Group 10 - Pretrain-finetuning part implemented by Alex.

Basic Info
  • Host: GitHub
  • Owner: COMP3340-2024-GP11
  • License: apache-2.0
  • Language: Jupyter Notebook
  • Default Branch: main
  • Size: 4.81 MB
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme Contributing License Citation

README.md

COMP3340 Group 10 - Pre-training

Contact

  • This repository contains code for various pre-training methods on COMP3340 course project CNN flower classification

  • For any question and enquiry, please feel free to reach out to HU Zhongyu (hzyalex@connect.hku.hk)

  • Thanks and enjoy =P

Overview

Prerequisite for Reproduction

  1. Set up conda environment

  2. Download data and checkpoint files and put them under the correct folder

  3. Run the commands to reproduce all the important results

Software, Hardware & System Requirements

  • Software

  • Set up environment as following

  • python==3.8.18

  • mmfewshot==0.1.0

  • mmdet==2.17.0

  • mmcv==1.3.14

  • Hardware

  • Experiments are conducted on one NVIDIA GeForce RTX 2080 Ti

  • System

  • Linux

Note

One model training typically takes 6-7 hours to run with one NVIDIA GeForce RTX 2080 Ti.

Environment setup

Basic Setup (Also required by some other Group 10 repos)

Step 1. Create virtual environment using anaconda

```

conda create -n open-mmlab python=3.8 -y

conda activate open-mmlab

```

Please make sure that you are create a virtual env with python version 3.8

Step 2 Install Pytorch from wheel

```

wget https://download.pytorch.org/whl/cu110/torch-1.7.1%2Bcu110-cp38-cp38-linuxx8664.whl#sha256=709cec07bb34735bcf49ad1d631e4d90d29fa56fe23ac9768089c854367a1ac9

pip install torch-1.7.1+cu110-cp38-cp38-linuxx8664.whl

```

Please double check that you install the correct version of pytorch using the following command

Output if correct pytorch version is installed

Step 3 Install cudatoolkit via conda-forge channel

You must be on the GPU compute node to install cudatoolkit and mmcv since GCC compiler and CUDA drivers only available on GPU computing nodes

```

gpu-interactive

conda activate open-mmlab

conda install -c conda-forge cudatoolkit=11.0

```

Step 4 Install torchvision, mmcv-full and mmcls package using pip

Make sure you are on GPU compute node!!

  • gpu-interactive

Make sure you did not previously installed any relevant package

Following pip show command show output a message like "no such package found"

```

pip show torchvision

pip show mmcv

pip show mmcv-full

pip show mmcls

```

remove pip cache

```

pip cache remove torchvision

pip cache remove mmcv

pip cache remove mmcv-full

pip cache remove mmcls

```

install packages

```

pip install torchvision==0.8.2

pip install mmcv-full==1.3.14 -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html

```

install mmclassification (mmcls-0.x)

git clone https://github.com/open-mmlab/mmclassification.git

cd mmclassification

pip install -v -e .

check installation

python demo/imagedemo.py demo/demo.JPEG resnet188xb32_in1k --device cpu

Download data & checkpoints

OneDrive Download Link

Contains:

  • Oxford-17 Flower Dataset

  • Oxford-102 Flower Dataset

  • Various saved trained model (as .pth checkpoint files) and training logs

  • Open-source pretrained model checkpoints

Move data to right place

  1. Download and unzip the "data" folder

  2. Move everything inside the "data" folder under mmclassification/data

Move checkpoints to right place

  1. Download and unzip the "output_pretrain" folder

  2. Move everything inside into "mmclassification/output"

  3. Download and unzip the "pretrain_checkpoint" folder

  4. Move everything inside into "mmclassification/resources" folder

Train & test

how to train

python tools/train.py --config [CONFIG FILE PATH] --work-dir [OUTPUT DIRECTORY PATH]

how to test

python tools/test.py --config [CONFIG FILE PATH] --checkpoint [.pth CHECKPOINT FILE PATH] --out [OUTPUT TEXT FILE PATH]

How to reproduce & evaluate our experiments

If you want to reproduce our experiment, just plug config file path and output directory path into the train command above

If you want to test trained model, just plug config file path and output directory path + "/latest.pth" into the test command above.

Also, corresponding training log files are inside the output folders

  1. Baseline: ResNet18, train from scratch for 200 epochs on oxford flower 17 dataset

config file: mmclassification/configs/resnet/resnet18flowersbs128.py

output directory:mmclassification/output/resnet18flowersbs128

  1. Finetune ResNet18 (pretrained on imagenet1k) on oxford flower 17

config:

mmclassification/configs/resnet/resnet18flowersfinetune.py

output:

mmclassification/output/resnet18flowerpretrainmodifiedparameter

  1. Finetune ResNet18 (pretrained on cifar10) on oxford flower 17

config: mmclassification/configs/resnet/resnet18flowersfinetune_cifar10.py

output:

mmclassification/output/resnet18pretraincifar10

  1. ResNet50 trained from scratch on oxford flower 17

config:

mmclassification/configs/resnet/resnet50_flowers.py

output:

mmclassification/output/resnet50

  1. Finetune ResNet50 (pretrained on cifar10) on oxford flower 17

config:

mmclassification/configs/resnet/resnet50flowersfinetune_cifar10.py

output:

mmclassification/output/resnet50flowercifar10

  1. Finetune ResNet50 (pretrained on cifar100) on oxford flower 17

config:

mmclassification/configs/resnet/resnet50flowersfinetune_cifar100.py

output:

mmclassification/output/resnet50flowercifar100

  1. Finetune ResNet50 (pretrained on imagenet1k) on oxford flower 17

config:

mmclassification/configs/resnet/resnet50flowersimagenet1k.py

output:

mmclassification/output/resnet50flowerimagenet1k

  1. Finetune ResNet50 (pretrained on imagenet21k) on oxford flower 17

config:

mmclassification/configs/resnet/resnet50flowersimagenet21k.py

output:

mmclassification/output/resnet50flowerimagenet21k

  1. ResNet152 trained from scratch on oxford flower 17

config:

mmclassification/configs/resnet/resnet152_flowers.py

output:

mmclassification/output/resnet152

  1. Finetune ResNet152 (pretrained on cifar10) on oxford flower 17

config:

mmclassification/configs/resnet/resnet152flowersfinetune_cifar10.py

output:

mmclassification/output/resnet152flowercifar10

Owner

  • Name: COMP3340 Group 10
  • Login: COMP3340-2024-GP11
  • Kind: organization

HKU COMP3340 Group 10 (2023-24 Second Semester)

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
title: "OpenMMLab's Image Classification Toolbox and Benchmark"
authors:
  - name: "MMClassification Contributors"
version: 0.15.0
date-released: 2020-07-09
repository-code: "https://github.com/open-mmlab/mmclassification"
license: Apache-2.0

GitHub Events

Total
Last Year

Dependencies

.github/workflows/build.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v1 composite
  • actions/setup-python v2 composite
  • codecov/codecov-action v1.0.10 composite
.github/workflows/deploy.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
docker/Dockerfile docker
  • pytorch/pytorch ${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel build
docker/serve/Dockerfile docker
  • pytorch/pytorch ${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel build
requirements/docs.txt pypi
  • docutils ==0.16.0
  • recommonmark *
  • sphinx ==4.0.2
  • sphinx_markdown_tables *
  • sphinx_rtd_theme ==0.5.2
requirements/mminstall.txt pypi
  • mmcv-full >=1.3.8,<=1.5.0
requirements/optional.txt pypi
  • albumentations >=0.3.2
requirements/readthedocs.txt pypi
  • mmcv >=1.3.8
  • torch *
  • torchvision *
requirements/runtime.txt pypi
  • matplotlib *
  • numpy *
requirements/tests.txt pypi
  • codecov * test
  • flake8 * test
  • interrogate * test
  • isort ==4.3.21 test
  • mmdet * test
  • pytest * test
  • xdoctest >=0.10.0 test
  • yapf * test
requirements.txt pypi
setup.py pypi