Skip to content

Commit

Permalink
Fixed COCO-Stuff splits
Browse files Browse the repository at this point in the history
Fixed Dataset for FSL step (filter not active yet)
Fixed Word-Embeddings for SPNet in COCO
  • Loading branch information
fcdl94 authored and fcdl94 committed Dec 29, 2020
1 parent 3ff19a3 commit 1ccd0ef
Show file tree
Hide file tree
Showing 20 changed files with 123,553 additions and 109 deletions.
53 changes: 34 additions & 19 deletions coco.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
#!/bin/bash

export CUDA_VISIBLE_DEVICES=$1
port=$2
alias exp="python -m torch.distributed.launch --master_port ${port} --nproc_per_node=1 run.py --opt_level O0"
alias exp="python -m torch.distributed.launch --master_port $2 --nproc_per_node=1 run.py --num_workers 8"
shopt -s expand_aliases

task=7mc
ds=coco
gen_par="--dataset coco --epochs 20 --batch_size 24 --crop_size 512 --val_interval 1"
#gen_par="--task ${task} --dataset voc --epochs 30 --batch_size 24 --crop_size 512 --val_interval 1"
#gen_par="--task voc --dataset coco-stuff --lr 0.01 --epochs 20 --batch_size 24 --crop_size 512 --val_interval 1"

path=checkpoints/step/spn-${ds}
lr=0.01

gen_par="--task ${task} --dataset ${ds} --batch_size 10 --crop_size 512"
exp --method SPN --name SPN ${gen_par} --step 0 --lr ${lr} --task 20-0
exp --method SPN --name SPN ${gen_par} --step 0 --lr ${lr} --task 20-1
exp --method SPN --name SPN ${gen_par} --step 0 --lr ${lr} --task 20-2

lr=0.0001 # for 1-shot, 15-1
iter=200

for is in 0 1 2 3 4; do
inc_par="--ishot ${is} --input_mix novel --val_interval 1000 --ckpt_interval 5 --no_pooling"
for ns in 1; do
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 FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
for step in 2 3 4 5 6 7; do
exp --method AMP --name AMP --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step ${step} --nshot ${ns}
exp --method FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step ${step} --nshot ${ns}
done
done
done
#export CUDA_VISIBLE_DEVICES=$1
#port=$2
#alias exp="python -m torch.distributed.launch --master_port ${port} --nproc_per_node=1 run.py --opt_level O0"
#shopt -s expand_aliases
#
#task=7mc
#ds=coco
#
#path=checkpoints/step/spn-${ds}
#
#gen_par="--task ${task} --dataset ${ds} --batch_size 10 --crop_size 512"
#
#lr=0.0001 # for 1-shot, 15-1
#iter=200
#
#for is in 0 1 2 3 4; do
#inc_par="--ishot ${is} --input_mix novel --val_interval 1000 --ckpt_interval 5 --no_pooling"
#for ns in 1; do
# 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 FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step 1 --nshot ${ns} --step_ckpt ${path}/FT_0.pth
# for step in 2 3 4 5 6 7; do
# exp --method AMP --name AMP --iter 0 --lr ${lr} ${gen_par} ${inc_par} --step ${step} --nshot ${ns}
# exp --method FT --name FT --iter ${iter} --lr ${lr} ${gen_par} ${inc_par} --step ${step} --nshot ${ns}
# done
# done
#done
30 changes: 30 additions & 0 deletions data/coco-stuff/make_annotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from PIL import Image
import numpy as np
import os
import os.path as osp
from tqdm import tqdm

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

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

# clear folder if exists
if osp.exists(nov_ann):
print("Removing existing")
os.rmdir(nov_ann)
os.makedirs(nov_ann)

# remap labels in the novel interval (+1 for Stuff, +1 and stuff on 0 for objects)
mapping = np.zeros((256,), dtype=np.int8)
for i, cl in enumerate(range(91)):
mapping[cl] = i + 1
mapping[255] = 255
target_transform = lambda x: Image.fromarray(mapping[x])

for f in tqdm(os.listdir(annotations)):
lbl = Image.open(osp.join(annotations, f))
lbl = target_transform(lbl)
lbl.save(osp.join(nov_ann, f))
Binary file added data/coco-stuff/split/inverse_dict_test_coco.pkl
Binary file not shown.
Loading

0 comments on commit 1ccd0ef

Please sign in to comment.