Skip to content

Commit 600679f

Browse files
committed
push.
1 parent d47a219 commit 600679f

15 files changed

+351
-55
lines changed

cifar.py

+51-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
parser = argparse.ArgumentParser()
3737
parser.add_argument("--mode", default="run", help="run, array, or job")
38+
parser.add_argument("--do_nonlinear", action="store_true", default=False)
3839
parser.add_argument(
3940
'--time',
4041
type=float,
@@ -339,6 +340,42 @@ def forward(self, x):
339340
# x = self.fc2(x)
340341
return x
341342

343+
344+
class NonLinearModel(nn.Module):
345+
def __init__(self, in_channels, num_classes, num_layers=3):
346+
super(LinearModel, self).__init__()
347+
self.in_channels = in_channels
348+
self.num_classes = num_classes
349+
self.num_layers = num_layers
350+
351+
self.nonlinear = nn.Sequential([
352+
nn.Sequential([
353+
nn.Linear(self.in_channels, self.in_channels),
354+
nn.ReLU()
355+
])
356+
for _ in num_layers
357+
])
358+
self.linear = nn.Linear(self.in_channels, self.num_classes)
359+
self.linear.weight.data.normal_(0, 0.01)
360+
self.linear.bias.data.zero_()
361+
362+
# self.fc1 = nn.Linear(self.in_channels, 512)
363+
# self.fc2 = nn.Linear(512, self.num_classes)
364+
# self.relu = nn.ReLU(inplace=True)
365+
# self.fc1.weight.data.normal_(0, 0.01)
366+
# self.fc1.bias.data.zero_()
367+
# self.fc2.weight.data.normal_(0, 0.01)
368+
# self.fc2.bias.data.zero_()
369+
370+
371+
def forward(self, x):
372+
x = x.view(x.size(0), -1)
373+
x = self.nonlinear(x)
374+
x = self.linear(x)
375+
# x = self.relu(self.fc1(x))
376+
# x = self.fc2(x)
377+
return x
378+
342379
#######################################################
343380
# Main
344381
#######################################################
@@ -370,6 +407,8 @@ def main(args):
370407

371408
# Build model
372409
# path = "/misc/kcgscratch1/ChoGroup/resnick/spaceofmotion/zeping/bsn"
410+
linear_cls = NonLinearModel if args.do_nonlinear else LinearModel
411+
373412
if args.model == "amdim":
374413
hparams = load_hparams_from_tags_csv('/checkpoint/cinjon/amdim/meta_tags.csv')
375414
# hparams = load_hparams_from_tags_csv(os.path.join(path, "meta_tags.csv"))
@@ -380,7 +419,7 @@ def main(args):
380419
model.load_state_dict(torch.load(_path)["state_dict"])
381420
else:
382421
print("AMDIM not loading checkpoint") # Debug
383-
linear_model = LinearModel(AMDIM_OUTPUT_DIM, args.num_classes)
422+
linear_model = linear_cls(AMDIM_OUTPUT_DIM, args.num_classes)
384423
elif args.model == "ccc":
385424
model = CCCModel(None)
386425
if not args.not_pretrain:
@@ -393,7 +432,7 @@ def main(args):
393432
model.load_state_dict(base_dict)
394433
else:
395434
print("CCC not loading checkpoint") # Debug
396-
linear_model = LinearModel(CCC_OUTPUT_DIM, args.num_classes).to(device)
435+
linear_model = linaer_cls(CCC_OUTPUT_DIM, args.num_classes) #.to(device)
397436
elif args.model == "corrflow":
398437
model = CORRFLOWModel(None)
399438
if not args.not_pretrain:
@@ -406,7 +445,7 @@ def main(args):
406445
model.load_state_dict(base_dict)
407446
else:
408447
print("CorrFlow not loading checkpoing") # Debug
409-
linear_model = LinearModel(CORRFLOW_OUTPUT_DIM, args.num_classes)
448+
linear_model = linear_cls(CORRFLOW_OUTPUT_DIM, args.num_classes)
410449
elif args.model == "resnet":
411450
if not args.not_pretrain:
412451
resnet = torchvision.models.resnet50(pretrained=True)
@@ -415,7 +454,7 @@ def main(args):
415454
print("ResNet not loading checkpoint") # Debug
416455
modules = list(resnet.children())[:-1]
417456
model = nn.Sequential(*modules)
418-
linear_model = LinearModel(RESNET_OUTPUT_DIM, args.num_classes)
457+
linear_model = linear_cls(RESNET_OUTPUT_DIM, args.num_classes)
419458
else:
420459
raise Exception("model type has to be amdim, ccc, corrflow or resnet")
421460

@@ -454,8 +493,9 @@ def main(args):
454493

455494
# Set up log dir
456495
now = datetime.datetime.now()
457-
log_dir = "{}{:%Y%m%dT%H%M}".format(args.model, now)
458-
log_dir = os.path.join("weights", log_dir)
496+
log_dir = '/checkpoint/cinjon/spaceofmotion/bsn/cifar-%d-weights/%s/%s' % (args.num_classes, args.model, args.name)
497+
# log_dir = "{}{:%Y%m%dT%H%M}".format(args.model, now)
498+
# log_dir = os.path.join("weights", log_dir)
459499
if not os.path.exists(log_dir):
460500
os.makedirs(log_dir)
461501
print("Saving to {}".format(log_dir))
@@ -557,7 +597,7 @@ def main(args):
557597
train_acc = 0
558598
train_loss_sum = 0.0
559599
for iter, input in enumerate(train_dataloader):
560-
if time.time() - start_time > args.time*3600 - 10 and comet_exp is not None:
600+
if time.time() - start_time > args.time*3600 - 300 and comet_exp is not None:
561601
comet_exp.end()
562602
sys.exit(-1)
563603

@@ -702,6 +742,10 @@ def main(args):
702742
val_acc = 0
703743
val_loss_sum = 0.0
704744
for iter, input in enumerate(val_dataloader):
745+
if time.time() - start_time > args.time*3600 - 300 and comet_exp is not None:
746+
comet_exp.end()
747+
sys.exit(-1)
748+
705749
imgs = input[0].to(device)
706750
if args.model != "resnet":
707751
imgs = imgs.unsqueeze(1)

compute.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import math
2+
import time
3+
import torch
4+
import torch.nn as nn
5+
import numpy as np
6+
7+
if __name__ == "__main__":
8+
a = np.load("/checkpoint/cinjon/spaceofmotion/bsn/test_reps_random_amdim.npy")
9+
a = a.reshape((a.shape[0], -1))
10+
a = a - np.mean(a, 0, keepdims=True)
11+
a = torch.from_numpy(a.T).half().to(0)
12+
print(a.size())
13+
b = np.load("/checkpoint/cinjon/spaceofmotion/bsn/test_reps_random_amdim.npy")
14+
b = b.reshape((b.shape[0], -1))
15+
# b_shape = b.shape
16+
# third_size = int(b_shape[0] / 3)
17+
b = b - np.mean(b, 0, keepdims=True)
18+
# b1 = b[:third_size, :]
19+
# b2 = b[third_size:, :]
20+
# b = b1
21+
22+
with torch.no_grad():
23+
b = torch.from_numpy(b).half().to(1)
24+
print(b.size())
25+
mat_mult = nn.Linear(in_features=b.shape[0], out_features=a.shape[0], bias=False)
26+
print(mat_mult.weight.size())
27+
mat_mult.weight.data = a
28+
mat_mult_gpu = nn.DataParallel(mat_mult, device_ids=[0, 1]).to('cuda:0')
29+
result = mat_mult_gpu(b.t())
30+
print(result.size())
31+
print(float(torch.norm(result.cpu())))
32+
# print(result.data.t())

gen_pem_results_jobs.py

+42-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,48 @@
6161
# CorrFLow NFC NF:
6262
4802: 1, 4779: 16,
6363
# CCC FT
64-
4560: 34, 4584: 32, 4572: 4, 4575: 3, 4554: 36, 4578: 14
64+
4560: 34, 4584: 32, 4572: 4, 4575: 3, 4554: 36, 4578: 14,
65+
# TSN Thumos DFC
66+
4896: 15, 4899: 28, 4902: 6, 4881: 9,
67+
# TSN THumos NFC Reg
68+
4863: 0, 4872: 12,
69+
# TSN Thumos NFC NF
70+
4914: 1, 4908: 0, 4923: 2, 4905: 1, 4911: 2, # Done
71+
# DFC Resnet Reg: Gym
72+
4971: 24, 4956: 21, 4965: 27, 4974: 26,
73+
# DFC Resnet-Rand: Gym
74+
5256: 30, 5244: 20, 5247: 28, 5238: 13, 5241: 30, 5262: 31, 5253: 27, # Done
75+
# NFC Resnet-Rand Reg: Gym
76+
5193: 10, 5175: 31, 5187: 25, 5181: 21, 5211: 13, 5199: 30, # Done
77+
# DFC Resnet NotRand: Thumos
78+
4989: 8, 4980: 10, # Done
79+
# DFC Resnet Rand: Thumos
80+
5343: 6, 5355: 3, 5319: 0, 5325: 1, 5349: 6, # Done
81+
# NFC Reg ResNet Rand: Thumos
82+
5307: 5, 5271: 2, 5274: 1, 5295: 2, 5277: 3, # Done
83+
# TSN Gym Rand NFC
84+
5370: 23, 5388: 29, 5373: 27, 5391: 23,
85+
# TSN Rand DFC:
86+
5445: 30, 5442: 26, # done
87+
# CorrFlow Rand DFC Gymnastics
88+
5712: 16, 5733: 18, 5742: 25, 5718: 4,
89+
# Corrflow Rand DFC ThumosImages
90+
5823: 2, 5802: 2, 5832: 9, 5808: 2,
91+
# CCC Thumos Rand dFC
92+
5646: 4, 5634: 6, 5619: 13, 5640: 2, 5628: 6, # done?
93+
# Thumos Resnet Rand NL DFC:
94+
6108: 6, 6123: 12, 6102: 5, 6090: 4, 6081: 4, 6114: 19,
95+
# Thumos Resnet Reg NL DFC:
96+
6030: 4, 6027: 25, 6015: 9, 6018: 24,
97+
# Gymnastics Resnet Rand NL DFC:
98+
6054: 26, 6048: 24, 6075: 32, 6069: 31, 6057: 21, 6078: 19, 6039: 21,
99+
# TSN Rnad DFC Thumos:
100+
5538: 8, 5547: 14,
101+
# Thumos Rand TSN NFC
102+
5475: 4, 5478: 24,
103+
# Gymnastics CCC Reg Rand:
104+
5565: 18, 5586: 18, 5559: 18, 5598: 18, 5571: 28, 5580: 18
105+
65106
}
66107

67108

gen_pgm_results_jobs.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
check = 0
2525
for tem_results_subdir in os.listdir(tem_results_dir):
2626
counter = int(regex.match(tem_results_subdir).groups()[0])
27+
2728

2829
print(tem_results_dir, tem_results_subdir, counter)
2930
job = run(find_counter=counter)

gen_postprocessed_results_jobs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
c2 = int(c2)
3838
counter = c2
3939

40-
print(pem_results_subdir, c1, c2)
40+
print(pem_results_subdir, c1, c2, '\n')
4141
if c1 in fixed:
4242
print('Got from fixed')
4343
job = fixed[c1]

gen_tem_results_jobs.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,51 @@
7070
# TSN Thumos NFC NF
7171
4908: 8, 4905: 8, 4911: 8, 4926: 8, 4923: 8, 4914: 8,
7272
# TSN Thumos DFC
73-
4881: 1, 4896: 3, 4899: 1, 4902: 3
73+
4881: 1, 4896: 3, 4899: 1, 4902: 3,
74+
# DFC Resnet Reg
75+
4971: 8, 4956: 3, 4965: 7, 4974: 6,
76+
# DFC Resnet-Rand
77+
5256: 19, 5244: 14, 5247: 13, 5238: 21, 5241: 22, 5262: 10, 5253: 7,
78+
# NFC Resnet-Rand Reg
79+
5193: 21, 5175: 12, 5187: 18, 5181: 13, 5211: 10, 5199: 8, # In the queue.
80+
# DFC Resnet NotRand:
81+
4989: 2, 4980: 3,
82+
# DFC Resnet Rand
83+
5343: 11, 5355: 25, 5319: 16, 5325: 24, 5349: 16,
84+
# NFC Reg ResNet Rand
85+
5307: 17, 5271: 17, 5274: 24, 5295: 13, 5277: 25, # done
86+
# TSN Gym Rand NFC:
87+
5370: 7, 5388: 5, 5373: 4, 5391: 7,
88+
# TSN Rand DFC
89+
5442: 3, 5445: 3, # done
90+
# CorrFlow Rand DFC Gymnastics
91+
5712: 7, 5733: 5, 5742: 7, 5718: 19,
92+
# Corrflow Rand DFC ThumosImages
93+
5823: 10, 5802: 10, 5832: 13, 5808: 18,
94+
# CCC Thumos Rand dFC
95+
5646: 9, 5634: 21, 5619: 4, 5640: 9, 5628: 13, # done
96+
# Thumos Resnet Rand NL DFC:
97+
6108: 10, 6123: 8, 6102: 16, 6090: 7, 6081: 11, 6114: 14,
98+
# Thumos Resnet Reg NL DFC:
99+
6030: 3, 6027: 3, 6015: 3, 6018: 3,
100+
# Gymnastics Resnet Rand NL DFC:
101+
6054: 10, 6048: 8, 6075: 8, 6069: 18, 6057: 9, 6078: 9, 6039: 24, # done
102+
# TSN Rnad DFC Thumos:
103+
5538: 3, 5547: 2,
104+
# Thumos Rand TSN NFC
105+
5475: 1, 5478: 1,
106+
# Gymnastics CCC Reg Rand:
107+
5565: 4, 5586: 4, 5559: 4, 5598: 4, 5571: 4, 5580: 4
74108
}
75109

76110

77111
num_gpus = 8
112+
check = 0
78113
for ns, ckpt_subdir in enumerate(sorted(os.listdir(ckpt_directory))):
79114
counter = int(regex.match(ckpt_subdir).groups()[0])
80115

81116
print(counter, ckpt_subdir)
82-
117+
83118
_job = run(find_counter=counter)
84119
if type(_job) == tuple:
85120
_job = _job[1]
@@ -104,6 +139,7 @@
104139
_job['time'] = 10
105140
print(_job['dataset'], _job['representation_module'], _job['do_feat_conversion'])
106141
# print(sorted(_job.items()))
142+
check += 1
107143
fb_run_batch(_job, counter, email, code_directory)
108144
print('\n')
109-
print(ns+1)
145+
print(ns+1, check)

main.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ def BSN_Train_TEM(opt):
305305
os.path.join(opt["checkpoint_path"], opt['name']))
306306
if opt['representation_checkpoint']:
307307
# print(model.representation_model.backbone.inception_5b_3x3.weight[0][0])
308-
partial_load(opt['representation_checkpoint'], model)
308+
if opt['do_random_model']:
309+
print('DOING RANDOM MDOEL!!!')
310+
else:
311+
print('DOING Pretrianed modelll!!!')
312+
partial_load(opt['representation_checkpoint'], model)
309313
# print(model.representation_model.backbone.inception_5b_3x3.weight[0][0])
310314
if not opt['no_freeze']:
311315
for param in model.representation_model.parameters():
@@ -798,16 +802,19 @@ def main(opt):
798802
counter, job = tem_jobs.run(find_counter=jobid)
799803
print(counter, job, '\n', opt)
800804
opt.update(job)
801-
print(opt, flush=True)
805+
print(sorted(opt.items()), flush=True)
802806
print('\n***\n%s\n***\n' % opt['do_feat_conversion'])
803807
if 'debug' in mode:
804808
opt.update({'num_gpus': 2, 'data_workers': 12,
805809
'name': 'dbg', 'counter': 0,
806-
'tem_batch_size': 1,
810+
'tem_batch_size': 1, 'do_feat_conversion': True,
807811
# 'gym_image_dir': '/checkpoint/cinjon/spaceofmotion/sep052019/rawframes.426x240.12',
808812
'local_comet_dir': None,
809813
'dataset': 'thumosimages',
810-
'video_info': '/private/home/cinjon/Code/BSN-boundary-sensitive-network.pytorch/data/thumos14_annotations', 'ccc_img_size': 128})
814+
'video_info': '/private/home/cinjon/Code/BSN-boundary-sensitive-network.pytorch/data/thumos14_annotations',
815+
'ccc_img_size': 128,
816+
# 'do_random_model': True
817+
})
811818

812819
if 'debugrun' not in mode:
813820
main(opt)

opts.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def parse_opt():
6868
parser.add_argument('--ccc_img_size', type=int, default=256)
6969
parser.add_argument('--tsn_config', type=str, default='~/Code/BSN-boundary-sensitive-network.pytorch/representations/tsn/temp_tsn_rgb_bninception.py')
7070

71+
7172
# PEM model settings
7273
parser.add_argument('--pem_feat_dim', type=int, default=32)
7374
parser.add_argument('--pem_hidden_dim', type=int, default=256)
@@ -143,7 +144,8 @@ def parse_opt():
143144
parser.add_argument('--do_augment', action='store_true')
144145
parser.add_argument('--do_representation', action='store_true')
145146
parser.add_argument('--do_feat_conversion', action='store_true')
146-
parser.add_argument('--no_freeze', action='store_true', default=False)
147+
parser.add_argument('--no_freeze', action='store_true', default=False)
148+
parser.add_argument('--do_random_model', action='store_true')
147149
parser.add_argument('--do_gradient_checkpointing', action='store_true', default=False)
148150
parser.add_argument(
149151
'--representation_module',

pem_jobs.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131

3232
def run(find_counter=None):
33-
counter = 950 # NOTE: adjust each time 451, 715, 750, 782, 814, 854
34-
33+
counter = 1622 # NOTE: adjust each time 451, 715, 750, 782, 814, 854, 950, 1054, 1150, 1382
34+
35+
check = 0
3536
for tem_results_subdir in sorted(os.listdir(tem_results_dir)):
3637
# if counter - start_counter > 100:
3738
# print('Stopping at %d' % counter)
@@ -98,12 +99,13 @@ def run(find_counter=None):
9899
__job['pem_lr_milestones'] = milestones
99100
__job['pem_step_gamma'] = pem_step_gamma
100101
__job['name'] = '%s-%05d' % (_job['name'], counter)
101-
102+
103+
check += 1
102104
if not find_counter:
103105
func(__job, counter, email, code_directory)
104106
elif counter == find_counter:
105107
return __job
106-
print(counter) # ended w 782, 814, 854, 950, 1054
108+
print(counter, check, check // 8) # ended w 782, 814, 854, 950, 1054, 1150, 1382, 1486, 1622
107109

108110
if __name__ == '__main__':
109111
run()

representations/amdim/representation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ def __init__(self, opts):
7272
self.repr_layer1 = self.make_layer(ResidualBlock, channels, channels, 2, stride=2)
7373
self.repr_layer2 = self.make_layer(ResidualBlock, channels, channels, 2, stride=2)
7474
if opts['dataset'] == 'gymnastics':
75-
self.fc_layer = nn.Linear(640, 400) # 2432
75+
self.fc_layer = nn.Linear(640, 400) # 2432, 640
7676
elif opts['dataset'] == 'thumosimages':
77-
self.fc_layer = nn.Linear(640, 400)
77+
self.fc_layer = nn.Linear(640, 400)
7878
elif opts['dataset'] == 'activitynet':
79-
self.fc_layer = nn.Linear(2432, 400)
79+
self.fc_layer = nn.Linear(640, 400)
8080

8181
def forward(self, representation):
8282
# thumosimages shape representation is [bs*nf, 2560, 75]

representations/corrflow/representation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, opts):
7575
if opts['dataset'] == 'gymnastics':
7676
self.fc_layer = nn.Linear(7168, 400) # 7168, 3584
7777
elif opts['dataset'] == 'thumosimages':
78-
self.fc_layer = nn.Linear(1920, 400) #
78+
self.fc_layer = nn.Linear(3840, 400) # 1920
7979
elif opts['dataset'] == 'activitynet':
8080
self.fc_layer = nn.Linear(2560, 400)
8181

0 commit comments

Comments
 (0)