Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bnneck implementation #10

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
78162ec
ignore dataset
bdockbockd Aug 28, 2020
e89155c
change parameter
bdockbockd Aug 28, 2020
5d42aca
Auto stash before merge of "master" and "origin/master"
bdockbockd Aug 30, 2020
55ddf0e
first commit
thanit456 Sep 1, 2020
7db1c90
add tensorboard in train.py
thanit456 Sep 1, 2020
a047d4a
merge-feat(log) : add tensorboard feat from too
bdockbockd Sep 3, 2020
d45d8e3
update repo
bdockbockd Sep 4, 2020
4cdac3f
update gitignore
bdockbockd Sep 4, 2020
7082fc5
update gitignore
bdockbockd Sep 4, 2020
2aef261
update struct
bdockbockd Sep 4, 2020
04f9402
Merge remote-tracking branch 'origin/master'
bdockbockd Sep 4, 2020
0a14b10
feat update demo template
bdockbockd Sep 5, 2020
cc1f23a
update struct
bdockbockd Sep 6, 2020
a76e881
add comment desc
bdockbockd Sep 6, 2020
8d91ec4
Merge remote-tracking branch 'origin/master'
bdockbockd Sep 6, 2020
70674ed
new clean git
bdockbockd Sep 6, 2020
c9988e3
merge from colab
bdockbockd Sep 6, 2020
7739795
refractor file
bdockbockd Sep 11, 2020
a95df42
Merge branch 'b_test' into origin/master
bdockbockd Sep 11, 2020
edcd45c
feat(oxygen_test) : create script to process image
bdockbockd Sep 11, 2020
95a2c9e
Merge branch 'master' into b_test
bdockbockd Sep 11, 2020
6296ad3
Merge remote-tracking branch 'origin/b_test'
bdockbockd Sep 12, 2020
bf10f30
feat(tools) : add visualize (retrieval) with no label
bdockbockd Sep 12, 2020
65f99c0
feat(script) : add script and guide for visualize-no-label
bdockbockd Sep 12, 2020
79316d5
tSNE or PCA visualization on test in tensorboard
thanit456 Sep 12, 2020
f207ee3
feat(tool) : complete feature for visualize with no label
bdockbockd Sep 12, 2020
846c7fb
refractor(code) : remove print line
bdockbockd Sep 12, 2020
40a187b
add new param in config and a script for visualizing loss
thanit456 Sep 13, 2020
4cbbf33
Merge branch 'master' into too_visualize_loss
bdockbockd Sep 17, 2020
4839d4e
Merge pull request #1 from beesk135/too_visualize_loss
bdockbockd Sep 17, 2020
7b22318
feat(visualize_no_label) : remove duplicate image from gallery
bdockbockd Sep 17, 2020
e17aad3
Merge remote-tracking branch 'origin/master'
bdockbockd Sep 17, 2020
ae6f175
feat(visualize_no_label) : add re_rank option
bdockbockd Sep 17, 2020
5581ad0
feat(visualize_no_label) : remove self index from ranking_list
bdockbockd Sep 17, 2020
3e4d54e
feat(tool) : fix re_rank bug
bdockbockd Sep 18, 2020
9aed0f5
feat(tool) : change pic name when add option rerank
bdockbockd Sep 18, 2020
cd364d9
feat(tool) : fix re_rank bug
bdockbockd Sep 18, 2020
c9d6372
feat(tool) : fix transfer & pre_train
bdockbockd Sep 18, 2020
a89f3c6
create the script to mock and convert labeller's dataset into market1…
thanit456 Sep 20, 2020
fcab311
Merge pull request #2 from beesk135/oxygen-dataset-preparation
thanit456 Sep 20, 2020
51c4a6d
add num distractors option excluding them from test set
thanit456 Sep 20, 2020
61c44da
Merge pull request #3 from beesk135/oxygen-dataset-preparation
thanit456 Sep 20, 2020
12a426f
feat(dataset) : add more dataset_prep
bdockbockd Sep 24, 2020
0924219
fix AGW_BASELINE config error
bdockbockd Sep 24, 2020
ee83c81
done baseline
bdockbockd Sep 24, 2020
ba143a0
done baseline
bdockbockd Sep 24, 2020
f51e11a
Auto stash before merge of "master" and "origin/master"
bdockbockd Sep 24, 2020
087e700
feat()
bdockbockd Sep 24, 2020
81a1005
feat(visualize) add rerank config
bdockbockd Sep 25, 2020
83ee354
refactor code and add several cosine methods
thanit456 Oct 5, 2020
b2fa8d1
add ArcFace implementation
thanit456 Oct 7, 2020
a0bb2f8
fix some configs for training market1501 on colab
thanit456 Oct 7, 2020
19fac83
fix import of pooling.py
thanit456 Oct 7, 2020
b3d1400
fix import @ baseline.py
thanit456 Oct 7, 2020
826c8b5
fix default config
thanit456 Oct 7, 2020
0f89dc3
fix passed arguments of config in baseline init
thanit456 Oct 7, 2020
86fe87f
fix default config
thanit456 Oct 7, 2020
d35f3bf
add incomplete re_rank_batch and fixed resnet_ibn_a
thanit456 Oct 7, 2020
be524d2
Merge pull request #4 from beesk135/cosface
thanit456 Oct 11, 2020
d595655
merge with new config
thanit456 Oct 11, 2020
a345e2e
add .gitignore
thanit456 Oct 11, 2020
ff0b71c
add .gitignore
thanit456 Oct 11, 2020
538936f
move center loss to solver section and adjust cosface_center baseline…
thanit456 Oct 12, 2020
d6cf3de
fix cosface_center config
thanit456 Oct 12, 2020
76f5340
use market pixel mean and std
thanit456 Oct 12, 2020
e7dce10
add arcface_baseline config
thanit456 Oct 12, 2020
e87f9b0
fix gem, arcface and add arcface config
thanit456 Oct 13, 2020
a8b5f1e
refactor losses
thanit456 Oct 13, 2020
94fa06f
create a build_loss
thanit456 Oct 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,22 @@ dmypy.json

# Pyre type checker
.pyre/

# Dataset
toDataset/
/gdrive/Shared drives/REID/ReId-Survey-Paper/ReID-Survey/log/
/content/gdrive/Shared drives/REID/ReId-Survey-Paper/ReID-Survey/toDataset/
/content/gdrive/Shared drives/REID/ReId-Survey-Paper/ReID-Survey/resnet50-19c8e357.pth
/content/gdrive/Shared drives/REID/ReId-Survey-Paper/ReID-Survey/log
/content/gdrive/Shared drives/REID/ReId-Survey-Paper/ReID-Survey/log/
*.pth
feature-pickle.pkl
*/feature-pickle.pkl
*.pkl
*.png
**/market1501/
**/test_image/
**/writer/
**/log
log/*
log/
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}
4 changes: 2 additions & 2 deletions Experiment-AGW-market.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
# weight regularized triplet loss
# generalized mean pooling
# non local blocks
python3 tools/main.py --config_file='configs/AGW_baseline.yml' MODEL.DEVICE_ID "('3')" \
DATASETS.NAMES "('market1501')" OUTPUT_DIR "('./log/market1501/Experiment-AGW-baseline')"
python3 tools/main.py --config_file='configs/AGW_baseline.yml' MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('market1501')" OUTPUT_DIR "('./log/market1501/AGW-new-conf-1')"
12 changes: 12 additions & 0 deletions Experiment-arcface_baseline-market.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dataset: market1501
# imagesize: 256x128
# batchsize: 16x4
# warmup_step 10
# random erase prob 0.5
# last stride 1
# with center loss
# weight regularized triplet loss
# generalized mean pooling
# non local blocks
python3 tools/main.py --config_file='configs/arcface_baseline.yml' MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('market1501')" OUTPUT_DIR "('./log/market1501/arcface_baseline-1')"
12 changes: 12 additions & 0 deletions Experiment-arcface_center-market.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dataset: market1501
# imagesize: 256x128
# batchsize: 16x4
# warmup_step 10
# random erase prob 0.5
# last stride 1
# with center loss
# weight regularized triplet loss
# generalized mean pooling
# non local blocks
python3 tools/main.py --config_file='configs/arcface_center.yml' MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('market1501')" OUTPUT_DIR "('./log/market1501/arcface_center-1')"
12 changes: 12 additions & 0 deletions Experiment-cosface_center-market.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dataset: market1501
# imagesize: 256x128
# batchsize: 16x4
# warmup_step 10
# random erase prob 0.5
# last stride 1
# with center loss
# weight regularized triplet loss
# generalized mean pooling
# non local blocks
python3 tools/main.py --config_file='configs/cosface_center.yml' MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('market1501')" OUTPUT_DIR "('./log/market1501/cosface_center-completed-1')"
7 changes: 7 additions & 0 deletions Test-Oxygen-Transfer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
python tools/main.py --config_file='configs/AGW_baseline.yml' \
MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('oxygen')" \
MODEL.PRETRAIN_CHOICE "('self')" \
TEST.WEIGHT "('./log/oxygen1/Experiment-AGW-baseline/resnet50_nl_model_120.pth')" \
TEST.EVALUATE_ONLY "('on')" \
OUTPUT_DIR "('./log/Oxygen_Test')"
6 changes: 6 additions & 0 deletions Train-Oxygen-Transfer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
python ./tools/main.py --config_file='configs/AGW_baseline.yml' \
MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('oxygen')" \
MODEL.TRANSFER_MODE "('on')" \
MODEL.PRETRAIN_CHOICE "('self')" \
MODEL.PRETRAIN_PATH "('./log/market1501/Experiment-AGW-baseline/resnet50_nl_model_160.pth')"
23 changes: 23 additions & 0 deletions Visalize-no-label.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# GO TO ROOT DIRECTORY
# rm -rf ./toDataset/oxygen1
# rm -rf ./toDataset/oxygen1/gallery
# mkdir ./toDataset/oxygen1
# mkdir ./toDataset/oxygen1/gallery
# Then you put oxygen folder in gallery folder
# And the structure must be like /gallery/mbk-12-4/*.jpg
# rm -rf ./log/oxygen1
# rm -rf ./log/oxygen1/query_image
# mkdir ./log/oxygen1
# mkdir ./log/oxygen1/query_image

# and run this command in single line
python ./tools/main.py --config_file='configs/AGW_baseline.yml' \
MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('oxygen1')" \
MODEL.PRETRAIN_CHOICE "('self')" \
TEST.WEIGHT "('/home/thanit456/capstone/ReID-Survey/log/market1501/local-AGW-baseline-2/resnet50_nl_model_120.pth')" \
VISUALIZE.OPTION "('on_no_label')" \
VISUALIZE.INDEX "(-1)" \
VISUALIZE.NEED_NEW_FEAT_EMBED "('off')" \
VISUALIZE.TOP_RANK "(20)" \
VISUALIZE.RE_RANK "('on')"
9 changes: 9 additions & 0 deletions Visualize-Oxygen-label.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
python ./tools/main.py --config_file='configs/AGW_baseline.yml' \
VISUALIZE.INDEX "(-1)" \
MODEL.DEVICE_ID "('0')" \
DATASETS.NAMES "('oxygen')" \
MODEL.PRETRAIN_CHOICE "('self')" \
TEST.WEIGHT "('./log/oxygen/Experiment-AGW-baseline/resnet50_nl_model_120.pth')" \
VISUALIZE.OPTION "('on')" \
OUTPUT_DIR "('./log/Oxygen/visualize_label_log.txt')"

11 changes: 11 additions & 0 deletions command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
conda create -n reid python=3.6
conda activate reid
pip install yacs
pip install -U scipy==1.2.0
conda install -c pytorch pytorch torchvision ignite==0.1.2

conda install ipykernel


# source activate reid
# python -m ipykernel install --user --name REID --display-name "Python (REID)"
60 changes: 49 additions & 11 deletions config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@
# ID number of GPU
_C.MODEL.DEVICE_ID = '0'
# Name of backbone
_C.MODEL.NAME = 'resnet50'
_C.MODEL.BACKBONE = 'resnet50'
# Last stride of backbone
_C.MODEL.LAST_STRIDE = 1
# Path to pretrained model of backbone
_C.MODEL.PRETRAIN_PATH = ''
_C.MODEL.TRANSFER_MODE ="off"
# Use ImageNet pretrained model to initialize backbone or use self trained model to initialize the whole model
# Options: 'imagenet' or 'self'
_C.MODEL.PRETRAIN_CHOICE = 'imagenet'
# If train with center loss, options: 'bnneck' or 'no'
_C.MODEL.CENTER_LOSS = 'on'
_C.MODEL.CENTER_FEAT_DIM = 2048
# If train with weighted regularized triplet loss, options: 'on', 'off'
_C.MODEL.WEIGHT_REGULARIZED_TRIPLET = 'off'
# If train with generalized mean pooling, options: 'on', 'off'
_C.MODEL.GENERALIZED_MEAN_POOL = 'off'

# If train with cos
_C.MODEL.USE_COS = False
# If train with dropout
_C.MODEL.USE_DROPOUT = False

# for baseline
_C.MODEL.BASELINE = CN()
_C.MODEL.BASELINE.POOL_TYPE = 'avg'
_C.MODEL.BASELINE.COSINE_LOSS_TYPE = ''
_C.MODEL.BASELINE.SCALING_FACTOR = 60.0
_C.MODEL.BASELINE.MARGIN = 0.35
_C.MODEL.BASELINE.USE_BNBIAS = False
_C.MODEL.BASELINE.USE_SESTN = False

# -----------------------------------------------------------------------------
# INPUT
Expand All @@ -49,6 +57,7 @@
_C.INPUT.PROB = 0.5
# Random probability for random erasing
_C.INPUT.RE_PROB = 0.5
_C.INPUT.RE_MAX_RATIO = 0.4
# Values to be used for image normalization
_C.INPUT.PIXEL_MEAN = [0.485, 0.456, 0.406]
# Values to be used for image normalization
Expand Down Expand Up @@ -90,10 +99,20 @@
_C.SOLVER.MOMENTUM = 0.9
# Margin of triplet loss
_C.SOLVER.MARGIN = 0.3
# Learning rate of SGD to learn the centers of center loss
_C.SOLVER.CENTER_LR = 0.5
# Balanced weight of center loss
_C.SOLVER.CENTER_LOSS_WEIGHT = 0.0005

###### Center loss ######

_C.SOLVER.CENTER_LOSS = CN()

_C.SOLVER.CENTER_LOSS.USE = False
# # Learning rate of SGD to learn the centers of center loss
_C.SOLVER.CENTER_LOSS.LR = 0.5
_C.SOLVER.CENTER_LOSS.WEIGHT = 0.0005
# _C.SOLVER.CENTER_LOSS.ALPHA = 1.0

_C.SOLVER.CENTER_LOSS.NUM_FEATS = 2048

##########################

# Settings of weight decay
_C.SOLVER.WEIGHT_DECAY = 0.0005
Expand Down Expand Up @@ -136,6 +155,25 @@
_C.TEST.FEAT_NORM = 'on'
_C.TEST.EVALUATE_ONLY = 'off'

# ---------------------------------------------------------------------------- #
# Visualize
# ---------------------------------------------------------------------------- #
_C.VISUALIZE = CN()
# option
_C.VISUALIZE.OPTION = "off"
_C.VISUALIZE.CAM_OPTION = "allow_other"
_C.VISUALIZE.IMS_PER_BATCH = 256
_C.VISUALIZE.NEED_NEW_FEAT_EMBED = "off"
_C.VISUALIZE.INDEX = 0
_C.VISUALIZE.TOP_RANK = 10
_C.VISUALIZE.RE_RANK = "off"
# ---------------------------------------------------------------------------- #
# Embedding projector
# ---------------------------------------------------------------------------- #
_C.EMBEDDING_PROJECTOR = CN()
# option
_C.EMBEDDING_PROJECTOR.OPTION = "off"

# ---------------------------------------------------------------------------- #
# Misc options
# ---------------------------------------------------------------------------- #
Expand Down
44 changes: 34 additions & 10 deletions configs/AGW_baseline.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
MODEL:
PRETRAIN_CHOICE: 'imagenet'
PRETRAIN_PATH: '/home/cgv841/.cache/torch/checkpoints/resnet50-19c8e357.pth'
CENTER_LOSS: 'on'
CENTER_FEAT_DIM: 2048
NAME: 'resnet50_nl'
# PRETRAIN_PATH: "/content/drive/Shared drives/REID/ReId-Survey-Paper/ReID-Survey/log/market1501/local-AGW-baseline/resnet50_nl_model_120.pth"
PRETRAIN_PATH: '/home/thanit456/torch/weights/resnet50-19c8e357.pth'
TRANSFER_MODE : 'off'
BACKBONE: 'resnet50_nl'
WEIGHT_REGULARIZED_TRIPLET: 'on'
GENERALIZED_MEAN_POOL: 'on'
USE_COS: False # unused config
USE_DROPOUT: False
BASELINE:
POOL_TYPE: 'gem'
COSINE_LOSS_TYPE: ''
SCALING_FACTOR: 60.0
MARGIN: 0.35

INPUT:
IMG_SIZE: [256, 128]
PROB: 0.5 # random horizontal flip
RE_PROB: 0.5 # random erasing
RE_MAX_RATIO: 0.4 # correspond to actual baseline
PADDING: 10

DATASETS:
Expand All @@ -25,12 +32,19 @@ SOLVER:
OPTIMIZER_NAME: 'Adam'
MAX_EPOCHS: 120
BASE_LR: 0.00035
MARGIN: 0.3

CENTER_LR: 0.5
CENTER_LOSS_WEIGHT: 0.0005
CENTER_LOSS:
USE: True
LR: 0.5
# ALPHA: 0.5
WEIGHT: 0.0005
NUM_FEATS: 2048

WEIGHT_DECAY: 0.0005
WEIGHT_DECAY: 5e-4
IMS_PER_BATCH: 64
# IMS_PER_BATCH: 32


STEPS: [40, 70]
GAMMA: 0.1
Expand All @@ -39,16 +53,26 @@ SOLVER:
WARMUP_ITERS: 10
WARMUP_METHOD: 'linear'

CHECKPOINT_PERIOD: 40
CHECKPOINT_PERIOD: 20
LOG_PERIOD: 20
EVAL_PERIOD: 40

TEST:
IMS_PER_BATCH: 128
IMS_PER_BATCH: 64
RE_RANKING: 'off'
WEIGHT: "path"
FEAT_NORM: 'on'
EVALUATE_ONLY: 'off'
VISUALIZE :
OPTION : "off"
IMS_PER_BATCH : 256
NEED_NEW_FEAT_EMBED : "off"
INDEX : 0
TOP_RANK : 10
RE_RANK : "off"
CAM_OPTION : "none"
EMBEDDING_PROJECTOR:
OPTION: "off"

OUTPUT_DIR: "./log/market1501/Experiment-AGW-baseline"

Expand Down
Loading