Skip to content

Commit

Permalink
Refactor for publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
fcdl94 authored and fcdl94 committed Nov 22, 2021
1 parent e89439a commit ef8db9e
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 106 deletions.
4 changes: 2 additions & 2 deletions data/coco/make_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from tqdm import tqdm

orig_path = '.' # insert here the source path where original COCO annotations are
dest_path = '.' # the destination folder, which should be this one'
dest_path = '.' # and the destination folder

for split in ["train2017", "val2017"]:
annotations = f"{orig_path}/annotations/{split}"
nov_ann = f"{dest_path}/annotations_my/{split}"
nov_ann = f"{dest_path}/annotations/{split}"

# clear folder if exists
if osp.exists(nov_ann):
Expand Down
16 changes: 13 additions & 3 deletions methods/segmentation_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ def make_model(opts, cls=None, head_channels=None):
if not opts.no_pretrained:
pretrained_path = f'pretrained/{opts.backbone}_iabn_sync.pth.tar' # Use always iabn_sync model
pre_dict = torch.load(pretrained_path, map_location='cpu')
del pre_dict['state_dict']['classifier.fc.weight']
del pre_dict['state_dict']['classifier.fc.bias']

body.load_state_dict(pre_dict['state_dict'])
new_state = {}
for k, v in pre_dict['state_dict'].items():
if "module" in k:
new_state[k[7:]] = v
else:
new_state[k] = v

if 'classifier.fc.weight' in new_state:
del new_state['classifier.fc.weight']
del new_state['classifier.fc.bias']

body.load_state_dict(new_state)
del pre_dict # free memory
del new_state

if cls is None:
if head_channels is None:
Expand Down
99 changes: 99 additions & 0 deletions run/voc-ms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash

export CUDA_VISIBLE_DEVICES=$1
port=$(python get_free_port.py)
echo ${port}
alias exp="python -m torch.distributed.launch --master_port ${port} --nproc_per_node=1 run.py --num_workers 4"
shopt -s expand_aliases

ds=voc
task=$2 # 5-0 5-1 5-2 5-3

# if you performed them for the SS experiment, comment the following!
exp --method FT --name FT --epochs 30 --lr 0.01 --batch_size 24
exp --method COS --name COS --epochs 30 --lr 0.01 --batch_size 24
exp --method SPN --name SPN --epochs 30 --lr 0.01 --batch_size 24
exp --method DWI --name DWI --epochs 30 --lr 0.01 --batch_size 24 --ckpt checkpoints/step/${task}-voc/COS_0.pth
exp --method RT --name RT --epochs 60 --lr 0.01 --batch_size 24 --ckpt checkpoints/step/${task}-voc/FT_0.pth --born_again

path=checkpoints/step/${task}-${ds}
task="${task}m"
gen_par="--task ${task} --dataset ${ds} --batch_size 10"
lr=0.0001 # for 1,2,5-shot
iter=200

# for 1 shot, disable the batch norm pooling on the deeplab head (or it'll throw errors) (--no_pooling)
for is in 0 1 2; do
inc_par="--ishot ${is} --input_mix novel --val_interval 1000 --ckpt_interval 5 --no_pooling"
ns=1

exp --method FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method WI --name WI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth
exp --method DWI --name DWI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/DWI_0.pth
exp --method RT --name RT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/RT_0.pth

exp --method SPN --name SPN --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/SPN_0.pth
exp --method AMP --name AMP --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method LWF --name LWF --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
exp --method ILT --name ILT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
exp --method MIB --name MIB --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method PIFS --name PIFS --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth

for s in 2 3 4 5; do
exp --method FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method WI --name WI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method DWI --name DWI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method RT --name RT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method SPN --name SPN --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method AMP --name AMP --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method LWF --name LWF --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method ILT --name ILT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method MIB --name MIB --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method PIFS --name PIFS --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
done
done

for ns in 2 5; do
for is in 0 1 2; do
inc_par="--ishot ${is} --input_mix novel --val_interval 1000 --ckpt_interval 5"

exp --method FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method WI --name WI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth
exp --method DWI --name DWI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/DWI_0.pth
exp --method RT --name RT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/RT_0.pth

exp --method SPN --name SPN --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/SPN_0.pth
exp --method AMP --name AMP --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method LWF --name LWF --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
exp --method ILT --name ILT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
exp --method MIB --name MIB --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method PIFS --name PIFS --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth

for s in 2 3 4 5; do
exp --method FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method WI --name WI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method DWI --name DWI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method RT --name RT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method SPN --name SPN --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method AMP --name AMP --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method LWF --name LWF --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method ILT --name ILT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
exp --method MIB --name MIB --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}

exp --method PIFS --name PIFS --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns}
done
done
done
41 changes: 41 additions & 0 deletions run/voc-ss.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

export CUDA_VISIBLE_DEVICES=$1
port=$(python get_free_port.py)
echo ${port}
alias exp="python -m torch.distributed.launch --master_port ${port} --nproc_per_node=1 run.py --num_workers 4"
shopt -s expand_aliases

ds=voc
task=$2

exp --method FT --name FT --epochs 30 --lr 0.01 --batch_size 24
exp --method COS --name COS --epochs 30 --lr 0.01 --batch_size 24
exp --method SPN --name SPN --epochs 30 --lr 0.01 --batch_size 24
exp --method DWI --name DWI --epochs 30 --lr 0.01 --batch_size 24 --ckpt checkpoints/step/${task}-voc/COS_0.pth
exp --method RT --name RT --epochs 60 --lr 0.01 --batch_size 24 --ckpt checkpoints/step/${task}-voc/FT_0.pth --born_again

gen_par="--task ${task} --dataset ${ds} --batch_size 10"
lr=0.001
iter=1000
path=checkpoints/step/${task}-${ds}
for ns in 1 2 5; do # shot 1/2/5 images
for is in 0 1 2; do # image samples
inc_par="--ishot ${is} --input_mix novel --val_interval 1000 --ckpt_interval 5"

exp --method FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method WI --name WI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth
exp --method DWI --name DWI --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/DWI_0.pth
exp --method RT --name RT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/RT_0.pth

exp --method SPN --name SPN --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/SPN_0.pth
exp --method AMP --name AMP --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method LWF --name LWF --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
exp --method ILT --name ILT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
exp --method MIB --name MIB --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth

exp --method PIFS --name PIFS --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth
done
done
57 changes: 57 additions & 0 deletions voc-ms_masked.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

export CUDA_VISIBLE_DEVICES=$1
port=$(python get_free_port.py)
echo ${port}
alias exp="python -m torch.distributed.launch --master_port ${port} --nproc_per_node=1 run.py --num_workers 4"
shopt -s expand_aliases

ds=voc
task=$2 # 5-0 5-1 5-2 5-3

exp --method FT --name FT --epochs 30 --lr 0.01 --batch_size 24
exp --method COS --name COS --epochs 30 --lr 0.01 --batch_size 24
exp --method SPN --name SPN --epochs 30 --lr 0.01 --batch_size 24
exp --method DWI --name DWI --epochs 30 --lr 0.01 --batch_size 24 --ckpt checkpoints/step/${task}-voc/COS_0.pth
exp --method RT --name RT --epochs 60 --lr 0.01 --batch_size 24 --ckpt checkpoints/step/${task}-voc/FT_0.pth --born_again

path=checkpoints/step/${task}-${ds}
task="${task}m"
gen_par="--task ${task} --dataset ${ds} --batch_size 10"
lr=0.0001 # for 1,2,5-shot
iter=200

# for 1 shot, disable the batch norm pooling on the deeplab head (or it'll throw errors) (--no_pooling)
for is in 0 1 2; do
inc_par="--ishot ${is} --input_mix novel --val_interval 1000 --ckpt_interval 5 --no_pooling"
ns=1
exp --method WI --name WI_mask --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth --masking
exp --method GIFS --name GIFS_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth --masking
exp --method GIFS --name GIFS_with_UCE_mask --mib_ce --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth --masking
exp --method MIB --name MIB_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth --masking

for s in 2 3 4 5; do
exp --method WI --name WI_mask --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
exp --method GIFS --name GIFS_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
exp --method GIFS --name GIFS_with_UCE_mask --mib_ce --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
exp --method MIB --name MIB_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
done
done

for ns in 2 5; do
for is in 0 1 2; do
inc_par="--ishot ${is} --input_mix novel --val_interval 1000 --ckpt_interval 5"
exp --method WI --name WI_mask --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth --masking
exp --method GIFS --name GIFS_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth --masking
exp --method GIFS --name GIFS_with_UCE_mask --mib_ce --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/COS_0.pth --masking
exp --method MIB --name MIB_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth --masking

for s in 2 3 4 5; do

exp --method WI --name WI_mask --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
exp --method GIFS --name GIFS_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
exp --method GIFS --name GIFS_with_UCE_mask --mib_ce --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
exp --method MIB --name MIB_mask --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step $s --nshot ${ns} --masking
done
done
done
101 changes: 0 additions & 101 deletions voc.sh

This file was deleted.

0 comments on commit ef8db9e

Please sign in to comment.