Skip to content

Commit

Permalink
fix issue 5
Browse files Browse the repository at this point in the history
  • Loading branch information
lvyiwei1 committed Oct 19, 2021
1 parent 521aa64 commit 8f827a4
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 18 deletions.
Binary file modified datasets/avmnist/__pycache__/get_data.cpython-38.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_MFM.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
objective=MFM_objective(2.0,[sigmloss1dcentercrop(28,34),sigmloss1dcentercrop(112,130)],[1.0,1.0])
train(encoders,fuse,head,traindata,validdata,25,decoders+intermediates,objective=objective,objective_args_dict={'decoders':decoders,'intermediates':intermediates})
model=torch.load('best.pt')
test(model,testdata)
test(model,testdata,no_robust=True)
2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_MVAE_mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
elbo=MVAE_objective(2.0,[sigmloss1dcentercrop(28,34),sigmloss1dcentercrop(112,130)],[1.0,1.0],annealing=0.0)
train(encoders,fuse,head,traindata,validdata,20,decoders,objective=elbo,objective_args_dict={'decoders':decoders})
mvae = torch.load('best.pt')
test(mvae,head,testdata)
test(mvae,testdata,no_robust=True)
2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_architecture_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

traindata, validdata, testdata = get_dataloader('/data/yiwei/avmnist/_MFAS/avmnist',batch_size=32)
model = torch.load('temp/best.pt').cuda()
test(model,testdata)
test(model,testdata,no_robust=True)
2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_cca.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@

print("Testing:")
model=torch.load('best_cca.pt').cuda()
test(model,testdata)
test(model,testdata,no_robust=True)
2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_gradient_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

print("Testing:")
model=torch.load(filename).cuda()
test(model,testdata)
test(model,testdata,no_robust=True)


2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_low_rank_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

print("Testing:")
model=torch.load(filename).cuda()
test(model,testdata)
test(model,testdata,no_robust=True)


2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_multi_interac_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

print("Testing:")
model=torch.load(filename).cuda()
test(model,testdata)
test(model,testdata,no_robust=True)


2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_refnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

print("Testing:")
model=torch.load('best.pt').cuda()
test(model,testdata)
test(model,testdata,no_robust=True)


6 changes: 3 additions & 3 deletions examples/multimedia/avmnist_simple_late_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from torch import nn
import torch

traindata, validdata, testdata = get_dataloader('/home/pliang/yiwei/avmnist/_MFAS/avmnist')
traindata, validdata, testdata = get_dataloader('/home/paul/yiwei/avmnist/_MFAS/avmnist')
channels=6
encoders=[LeNet(1,channels,3).cuda(),LeNet(1,channels,5).cuda()]
head=MLP(channels*40,100,10).cuda()

fusion=Concat().cuda()

train(encoders,fusion,head,traindata,validdata,30,optimtype=torch.optim.SGD,lr=0.1,weight_decay=0.0001)
train(encoders,fusion,head,traindata,validdata,3,optimtype=torch.optim.SGD,lr=0.1,weight_decay=0.0001)

print("Testing:")
model=torch.load('best.pt').cuda()
test(model,testdata)
test(model,testdata,no_robust=True)


2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_tensor_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

print("Testing:")
model=torch.load('best.pt').cuda()
test(model,testdata)
test(model,testdata,no_robust=True)


2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_unimodal_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
print("Testing:")
encoder=torch.load('encoder.pt').cuda()
head = torch.load('head.pt')
test(encoder,head,testdata,modalnum=modalnum)
test(encoder,head,testdata,modalnum=modalnum,no_robust=True)


2 changes: 1 addition & 1 deletion examples/multimedia/avmnist_unimodal_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
print("Testing:")
encoder=torch.load('encoder.pt').cuda()
head = torch.load('head.pt')
test(encoder,head,testdata,modalnum=modalnum)
test(encoder,head,testdata,modalnum=modalnum,no_robust=True)


Binary file modified fusions/__pycache__/common_fusions.cpython-38.pyc
Binary file not shown.
7 changes: 6 additions & 1 deletion training_structures/Supervised_Learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,12 @@ def processinput(inp):
# criterion: only needed for regression, put MSELoss there
# all other arguments are same as train
def test(
model, test_dataloaders_all, dataset, method_name='My method', is_packed=False, criterion=nn.CrossEntropyLoss(), task="classification", auprc=False, input_to_float=True):
model, test_dataloaders_all, dataset='default', method_name='My method', is_packed=False, criterion=nn.CrossEntropyLoss(), task="classification", auprc=False, input_to_float=True, no_robust=False):
if no_robust:
def testprocess():
single_test(model,test_dataloaders_all,is_packed,criterion,task,auprc,input_to_float)
all_in_one_test(testprocess,[model])
return
def testprocess():
single_test(model, test_dataloaders_all[list(test_dataloaders_all.keys())[0]][0], is_packed, criterion, task, auprc, input_to_float)
all_in_one_test(testprocess, [model])
Expand Down
7 changes: 6 additions & 1 deletion training_structures/architecture_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ def single_test(model,test_dataloader,auprc=False):
return {'Accuracy': float(corrects)/total}


def test(model, test_dataloaders_all, dataset, method_name='My method', auprc=False):
def test(model, test_dataloaders_all, dataset, method_name='My method', auprc=False, no_robust=False):
if no_robust:
def testprocess():
single_test(model,test_dataloaders_all, auprc)
all_in_one_test(testprocess,[model])
return
def testprocess():
single_test(model, test_dataloaders_all[list(test_dataloaders_all.keys())[0]][0], auprc)
all_in_one_test(testprocess, [model])
Expand Down
7 changes: 6 additions & 1 deletion training_structures/gradient_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,12 @@ def single_test(model, test_dataloader, auprc=False, classification=True):
return {'MSE': (totalloss/total).item()}


def test(model, test_dataloaders_all, dataset, method_name='My method', auprc=False, classification=True):
def test(model, test_dataloaders_all, dataset, method_name='My method', auprc=False, classification=True,no_robust=False):
if no_robust:
def testprocess():
single_test(model,test_dataloaders_all,auprc,classification)
all_in_one_test(testprocess,[model])
return
def testprocess():
single_test(model, test_dataloaders_all[list(test_dataloaders_all.keys())[0]][0], auprc, classification)
all_in_one_test(testprocess, [model])
Expand Down
7 changes: 6 additions & 1 deletion training_structures/unimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ def single_test(encoder, head, test_dataloader, auprc=False, modalnum=0, task='c
return {'MSE': (totalloss / totals).item()}


def test(encoder, head, test_dataloaders_all, dataset, method_name='My method', auprc=False, modalnum=0, task='classification', criterion=None):
def test(encoder, head, test_dataloaders_all, dataset='default', method_name='My method', auprc=False, modalnum=0, task='classification', criterion=None,no_robust=False):
if no_robust:
def testprocess():
single_test(encoder,head,test_dataloaders_all,auprc,modalnum,task,criterion)
all_in_one_test(testprocess,[model])
return
def testprocess():
single_test(encoder, head, test_dataloaders_all[list(test_dataloaders_all.keys())[0]][0], auprc, modalnum, task, criterion)
all_in_one_test(testprocess, [encoder, head])
Expand Down

0 comments on commit 8f827a4

Please sign in to comment.