def plot_roc(): y_preds = [] y_=[] name_list = ['vgg+fc','densenet121+fc','iv3+fc','resnet50+fc'] vggroot = "/Users/lizhenhao/Desktop/helloworld/im/vgg" vgg=fc.get_model(25088) vgg.load_weights("/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/vgg/epoch-19.h5") test_f, test_y = getdata_fromtxt(vggroot + '/test.txt') test_y_pred = vgg.predict(test_f) test_y_pred = test_y_pred.reshape(-1) y_preds.append(test_y_pred) y_.append(test_y) denseroot = "/Users/lizhenhao/Desktop/helloworld/im/densenet" den = fc.get_model(50176) den.load_weights("/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/densenet/epoch-19.h5") test_f, test_y = getdata_fromtxt(denseroot + '/test.txt') test_y_pred = den.predict(test_f) test_y_pred = test_y_pred.reshape(-1) y_preds.append(test_y_pred) y_.append(test_y) iv3root = "/Users/lizhenhao/Desktop/helloworld/im/iv3" iv3 = fc.get_model(51200) iv3.load_weights("/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/iv3/epoch-19.h5") test_f, test_y = getdata_fromtxt(iv3root + '/test.txt') test_y_pred = iv3.predict(test_f) test_y_pred = test_y_pred.reshape(-1) y_preds.append(test_y_pred) y_.append(test_y) resroot = "/Users/lizhenhao/Desktop/helloworld/im/resnet50" res = fc.get_model(2048) res.load_weights("/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/resnet50/epoch-19.h5") test_f, test_y = getdata_fromtxt(resroot + '/test.txt') test_y_pred = res.predict(test_f) test_y_pred = test_y_pred.reshape(-1) y_preds.append(test_y_pred) y_.append(test_y) draw.draw_roc(y_, y_preds, name_list, 'roc.png')
def densenettrain(): print("densenet begin") model = fc.get_model(50176) root = '/Users/lizhenhao/Desktop/helloworld/im/densenet' weights_savedir = "/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/densenet" acc_savepath = "/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/densenet/acc.png" loss_savepath = "/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/densenet/loss.png" train_f, train_y = getdata_fromtxt(root + '/train.txt') vali_f, vali_y = getdata_fromtxt(root + '/vali.txt') test_f, test_y = getdata_fromtxt(root + '/test.txt') mycall = mycallback(test_f, test_y, weights_savedir) model.compile(loss=tf.keras.losses.binary_crossentropy, optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), metrics=[tf.keras.metrics.binary_accuracy]) model.fit(train_f, train_y, epochs=20, shuffle=True, validation_data=(vali_f, vali_y), callbacks=[mycall]) draw.draw_acc(mycall.train_acc, mycall.vali_acc, mycall.test_acc, mycall.epoch, acc_savepath) draw.draw_loss(mycall.train_loss, mycall.vali_loss, mycall.test_loss, mycall.epoch, loss_savepath) print('densenet done') return model