Skip to content

Commit

Permalink
feat: implement manufact_80 works and finetune indoor_80
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangboom committed Nov 5, 2024
1 parent 2cfcff8 commit dbe5606
Show file tree
Hide file tree
Showing 12 changed files with 6,472 additions and 327 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ run_scripts/finetune/polyformer_b_aihub_manufact_checkpoints
run_scripts/finetune/polyformer_b_aihub_manufact_logs
run_scripts/finetune/polyformer_l_checkpoints
run_scripts/finetune/polyformer_l_logs
run_scripts/pretrain/polyformer_b_pretrain_aihub_indoor_80_logs_resume_2/
results_polyformer_b
weights

Expand Down
Binary file modified data/__pycache__/refcoco_dataset.cpython-37.pyc
Binary file not shown.
12 changes: 8 additions & 4 deletions data/create_aihub_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

data_root = './refer/data'
# datasets = ['refcoco', 'refcoco+', 'refcocog']
datasets = ['aihub_indoor']
# datasets = ['aihub_manufact']
# datasets = ['aihub_indoor']
datasets = ['aihub_manufact']

if datasets[0] == 'aihub_indoor':
image_dir = './refer/data/aihub_refcoco_format/indoor_80/images'
elif datasets[0] == 'aihub_manufact':
image_dir = './refer/data/aihub_refcoco_format/manufact/images'
image_dir = './refer/data/aihub_refcoco_format/manufact_80/images'
else:
image_dir = './datasets/images/mscoco/train2014'
val_test_files = pickle.load(open("data/val_test_files.p", "rb"))
Expand All @@ -46,6 +46,7 @@
splits = ['train', 'val']
splitBy = None
elif dataset == 'aihub_manufact':
# splits = ['val', 'test']
splits = ['train', 'val', 'test']
splitBy = None

Expand All @@ -66,7 +67,10 @@
writer = open(file_name, 'w')
refer = REFER(data_root, dataset, splitBy)

ref_ids = refer.getRefIds(split=split)
if dataset == 'aihub_manufact' and split == 'val':
ref_ids = refer.getRefIds(split='validation')
else:
ref_ids = refer.getRefIds(split=split)

for this_ref_id in tqdm(ref_ids):
this_img_id = refer.getImgIds(this_ref_id)
Expand Down
21 changes: 12 additions & 9 deletions data/create_pretraining_aihub_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import pickle


img_path = 'refer/data/aihub_refcoco_format/indoor_80/images'
# img_path = 'refer/data/aihub_refcoco_format/indoor/images'
# img_path = 'refer/data/aihub_refcoco_format/indoor_80/images'
img_path = 'refer/data/aihub_refcoco_format/manufact_80/images'

# load annotation files
# f = open("datasets/annotations/instances.json")
f = open("refer/data/aihub_refcoco_format/indoor_80/instances.json")
# f = open("refer/data/aihub_refcoco_format/manufact/instances.json")
# f = open("refer/data/aihub_refcoco_format/indoor_80/instances.json")
f = open("refer/data/aihub_refcoco_format/manufact_80/instances.json")
print("Loading annotation file")
data = json.load(f)
f.close()
Expand All @@ -35,8 +35,8 @@
print(len(data['images']))
print(len(data['annotations']))

ref_file = 'refer/data/aihub_refcoco_format/indoor_80/refs.p'
# ref_file = 'refer/data/aihub_refcoco_format/manufact/refs.p'
# ref_file = 'refer/data/aihub_refcoco_format/indoor_80/refs.p'
ref_file = 'refer/data/aihub_refcoco_format/manufact_80/refs.p'
ref_ann = pickle.load(open(ref_file, 'rb'))
print(ref_ann[10])
print(ref_ann[1])
Expand All @@ -51,7 +51,8 @@
# exit()


tsv_filename = "datasets/pretrain/train_aihub_indoor_80_test.tsv"
# tsv_filename = "datasets/pretrain/train_aihub_indoor_80_test.tsv"
tsv_filename = "datasets/pretrain/train_aihub_manufact_80.tsv"
writer = open(tsv_filename, 'w')
print("generating ", tsv_filename)

Expand Down Expand Up @@ -80,6 +81,7 @@
# print("train!!")
pass
else:
# print(ref_ann_i['split'])
# print("It's validation or test data")
continue

Expand Down Expand Up @@ -117,7 +119,8 @@

#####################################
# generate validation tsv files
tsv_filename = f"datasets/pretrain/val_aihub_indoor_80.tsv"
# tsv_filename = f"datasets/pretrain/val_aihub_indoor_80.tsv"
tsv_filename = f"datasets/pretrain/val_aihub_manufact_80.tsv"
writer = open(tsv_filename, 'w')
print("generating ", tsv_filename)

Expand All @@ -132,7 +135,7 @@

# ref_ann_i = next((d for d in ref_ann if d["ref_id"] == str(i)), None)
# ref_ann_i = ref_ann[i]
if ref_ann_i['split'] == 'val':
if ref_ann_i['split'] == 'validation':
# print("val!!")
pass
else:
Expand Down
16 changes: 14 additions & 2 deletions data/refcoco_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import utils.transforms as T
import math
# from PIL import ImageFile
from PIL import Image, ImageFile
from PIL import Image, ImageFile, UnidentifiedImageError
# import Image

from data import data_utils
Expand Down Expand Up @@ -92,7 +92,19 @@ def __getitem__(self, index):
# print(BytesIO(base64.urlsafe_b64decode(base64_str)))

# image = Image.open(BytesIO(base64.urlsafe_b64decode(base64_str))).convert("RGB")
image = Image.open(BytesIO(base64.b64decode(base64_str))).convert("RGB")
try:
image = Image.open(BytesIO(base64.b64decode(base64_str))).convert("RGB")
# except UnidentifiedImageError:
except:
data = self.dataset[index+1]
if len(data) == 7:
uniq_id, base64_str, seg64_str, text, poly_original, region_coord, poly_interpolated = data
train = True
else:
uniq_id, base64_str, seg64_str, text, poly, region_coord = data
train = False
image = Image.open(BytesIO(base64.b64decode(base64_str))).convert("RGB")


label = Image.open(BytesIO(base64.urlsafe_b64decode(seg64_str)))
label = np.asarray(label)
Expand Down
8 changes: 5 additions & 3 deletions refer/refer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def __init__(self, data_root, dataset='refcoco', splitBy='unc'):
# print(os.listdir(self.IMAGE_DIR))
elif dataset == 'aihub_manufact':
# self.DATA_DIR = osp.join(data_root, 'refcocog')
self.DATA_DIR = "refer/data/aihub_refcoco_format/manufact"
self.IMAGE_DIR = "refer/data/aihub_refcoco_format/manufact/images"
self.DATA_DIR = "refer/data/aihub_refcoco_format/manufact_80"
self.IMAGE_DIR = "refer/data/aihub_refcoco_format/manufact_80/images"
print('Dataset preprocessing...')
print('Print list of AIHub Manufact dataset...')
# print(os.listdir(self.IMAGE_DIR))
Expand Down Expand Up @@ -142,7 +142,7 @@ def createIndex(self):
for sent in ref['sentences']:
Sents[sent['sent_id']] = sent
sentToRef[sent['sent_id']] = ref
sentToTokens[sent['sent_id']] = sent['tokens']
# sentToTokens[sent['sent_id']] = sent['tokens']

# create class members
self.Refs = Refs
Expand Down Expand Up @@ -184,6 +184,8 @@ def getRefIds(self, image_ids=[], cat_ids=[], ref_ids=[], split=''):
refs = [ref for ref in refs if 'test' in ref['split']]
elif split == 'train' or split == 'val':
refs = [ref for ref in refs if ref['split'] == split]
elif split == 'validation':
refs = [ref for ref in refs if ref['split'] == split]
else:
print ('No such split [%s]' % split)
sys.exit()
Expand Down
5 changes: 3 additions & 2 deletions run_scripts/evaluation/evaluate_polyformer_b_aihub_indoor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ num_bins=64
batch_size=16

dataset='aihub_indoor'
ckpt_path=../finetune/polyformer_b_aihub_indoor_checkpoints/100_5e-5_512/checkpoint_epoch_1.pt
ckpt_path=../finetune/polyformer_b_aihub_indoor_80_checkpoints/100_5e-5_512/checkpoint_epoch_61.pt
# dataset='refcocog'
# ckpt_path=../../weights/polyformer_b_refcocog.pt

# for split in 'refcocog_val' 'refcocog_test'
for split in 'aihub_indoor_val' 'aihub_indoor_test'
# for split in 'aihub_indoor_val' 'aihub_indoor_test'
for split in 'aihub_indoor_val'
do
data=../../datasets/finetune/${dataset}/${split}.tsv
result_path=../../results_${model}/${dataset}/
Expand Down
6,727 changes: 6,425 additions & 302 deletions run_scripts/finetune/polyformer_b_aihub_indoor_80_logs/100_5e-5_512.log

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion run_scripts/finetune/train_polyformer_b_aihub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data=${data_dir}/aihub_indoor/aihub_indoor_train.tsv,${data_dir}/aihub_indoor/ai
selected_cols=0,5,6,2,4,3,7
# restore_file=../../weights/polyformer_b_pretrain.pt
# restore_file=../pretrain/polyformer_b_pretrain_aihub_indoor_checkpoints/20_5e-5_512/checkpoint_20_1000.pt
restore_file=../pretrain/polyformer_b_pretrain_aihub_indoor_80_checkpoints_resume/20_5e-5_512/checkpoint.best_score_0.5110.pt
restore_file=../pretrain/polyformer_b_pretrain_aihub_indoor_80_checkpoints_resume_2/20_5e-5_512/checkpoint.best_score_0.5220.pt



Expand Down
7 changes: 3 additions & 4 deletions run_scripts/pretrain/pretrain_polyformer_b_aihub_indoor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export MASTER_PORT=6061
det_weight=1
cls_weight=0
num_bins=64
log_dir=./polyformer_b_pretrain_aihub_indoor_80_logs_resume
save_dir=./polyformer_b_pretrain_aihub_indoor_80_checkpoints_resume
log_dir=./polyformer_b_pretrain_aihub_indoor_80_logs_resume_2
save_dir=./polyformer_b_pretrain_aihub_indoor_80_checkpoints_resume_2
mkdir -p $log_dir $save_dir

bpe_dir=../../utils/BPE
Expand Down Expand Up @@ -39,8 +39,7 @@ max_tgt_length=420

patch_image_size=512

restore_file=../pretrain/polyformer_b_pretrain_aihub_indoor_80_checkpoints/20_5e-5_512/checkpoint_16_5000.pt

restore_file=../pretrain/polyformer_b_pretrain_aihub_indoor_80_checkpoints_resume/20_5e-5_512/checkpoint.best_score_0.5110.pt

for max_epoch in 20; do
echo "max_epoch "${max_epoch}
Expand Down
Binary file modified utils/__pycache__/eval_utils.cpython-37.pyc
Binary file not shown.
Binary file modified utils/__pycache__/vis_utils.cpython-37.pyc
Binary file not shown.

0 comments on commit dbe5606

Please sign in to comment.