def create_net(model, img_prep, img_aug, learning_rate): if model == "alex": network = alexNet(img_prep, img_aug, learning_rate) elif model == "vgg": network = vggNet(img_prep, img_aug, learning_rate) elif model == "res": network = resNet(img_prep, img_aug, learning_rate) elif model == "alch11": network = alchNet11(img_prep, img_aug, learning_rate) elif model == "alch11_without_dropout": network = alchNet11(img_prep, img_aug, learning_rate, 0) else: network = alchNet19(img_prep, img_aug, learning_rate) return network
def create_net(model, img_prep, img_aug, learning_rate): if model == "alex": network = alexNet(img_prep, img_aug, learning_rate) elif model == "vgg": network = vggNet(img_prep, img_aug, learning_rate) elif model == "vggtop5": network = vggNetTop5(img_prep, img_aug, learning_rate) elif model == "vgg13": network = vggNet13(img_prep, img_aug, learning_rate) elif model == "vgg16": network = vggNet16(img_prep, img_aug, learning_rate) elif model == "res": network = resNet(img_prep, img_aug, learning_rate) elif model == "alch11": network = alchNet11(img_prep, img_aug, learning_rate) elif model == "alch11_without_dropout": network = alchNet11(img_prep, img_aug, learning_rate, 0) elif model == "alch_enhance": network = alchNetEnhance(img_prep, img_aug, learning_rate) else: network = alchNet19(img_prep, img_aug, learning_rate) return network
batch_size=batch_size, n_channels=1, n_classes=n_classes, shuffle=True) validation_generator = volume.DataGenerator(validationlistIDs, validationdataDir, v_size=sideLength, batch_size=batch_size, n_channels=1, n_classes=n_classes, shuffle=True) ##------------------------------ Model ---------------------------------------## #Create model = models.alexNet(sideLength) model.summary() #Track accuracy and loss in real-time #if jupyter notebook: log_dir = "/media/data_crypt_2/alexNet" + datetime.datetime.now().strftime( "%Y-%m-%d_%H:%M:%S") file_writer = tf.summary.create_file_writer(log_dir + "/metrics") file_writer.set_as_default() #python script saving_path = log_dir if not os.path.isdir(saving_path): os.mkdir(saving_path) saving_path = os.path.join(saving_path, 'metricsHistory') if not os.path.isdir(saving_path):
] epochs = [i for i in range(1, 51)] #CHANGE THIS a = len(testinglistIDs) print('total of {} testing images'.format(a)) step = math.ceil(a / 16) batch_size = 128 #CHANGE THIS sideLength = 96 #CHANGE THIS test_generator = testDataGenerator(testinglistIDs, testDir, batch_size=batch_size, v_size=sideLength) model = models.alexNet(sideLength) #CHANGE THIS for epoch in epochs: model.load_weights( "/data/resized_FPR/models/improved_res_alex_aug/2021-02-16_11:57:24/checkpoints/alex_aug_{}.hd5f" .format(str(epoch).zfill(2))) #CHANGE THIS opt = SGD() model.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy']) #CHANGE THIS (OPTIMIZER) prediction = model.evaluate(test_generator, verbose=1) savePath = '/data/resized_FPR/models/improved_res_alex_aug/2021-02-16_11:57:24/evaluation' #CHANGE THIS if not os.path.isdir(savePath): os.mkdir(savePath) with open(os.path.join(savePath, 'eval_epoch{}.txt'.format(epoch)), 'w+') as f:
if model == 'res18conv': # ResNet18 Conv model, criterion, optimizer, scheduler = models.resNet18_conv() model_conv = fit(model, criterion, optimizer, scheduler, num_epochs=30) predict(model_conv) if model == 'res152conv': # ResNet152 Conv model, criterion, optimizer, scheduler = models.resNet152_conv() model_conv = fit(model, criterion, optimizer, scheduler, num_epochs=30) predict(model_conv) if model == 'dense161': # DenseNet161 model, criterion, optimizer, scheduler = models.denseNet161_ft() model_ft = fit(model, criterion, optimizer, scheduler, num_epochs=30) predict(model_ft) if model == 'vgg19': # VGG 19-layer model model, criterion, optimizer, scheduler = models.vgg19() model_ft = fit(model, criterion, optimizer, scheduler, num_epochs=30) predict(model_ft) if model == 'alex': # AlexNet model, criterion, optimizer, scheduler = models.alexNet() model_ft = fit(model, criterion, optimizer, scheduler, num_epochs=30) predict(model_ft)