def test_alexnet(): from keras.models import load_model import numpy as np import time test_dir= '/home/pdd/pdwork/CV_BiShe/picture/trainTest/' test, test_label = get_files(test_dir, 224, 224) TP = 0 TN = 0 FP = 0 FN = 0 model = load_model('resnet50.h5') time_start=time.time() test_result = model.predict(test) time_end=time.time() time_spent = time_end-time_start print(time_spent) #calc precision and recall for i in range(0,len(test_label)): if np.argmax(test_result[i]) == 1: if np.argmax(test_label[i]) == 1: TP += 1 else: FP += 1 else: if np.argmax(test_label[i]) == 1: FN += 1 else: TN += 1 precision = TP/(FP+TP) recall = TP/(FN+TP) print('precision', precision) print('recall', recall) return time_spent, precision, recall
FN = 0 model = load_model('vgg16.h5') test_result = model.predict(test) time_end = time.time() time_spent = time_end - time_start print(time_spent) #calc precision and recall for i in range(0, len(test_label)): if np.argmax(test_result[i]) == 1: if np.argmax(test_label[i]) == 1: TP += 1 else: FP += 1 else: if np.argmax(test_label[i]) == 1: FN += 1 else: TN += 1 precision = TP / (FP + TP) recall = TP / (FN + TP) print('precision', precision) print('recall', recall) return time_spent, precision, recall train_dir = "/home/pdd/pdwork/CV_BiShe/picture/picTrain" train, train_label = get_files(train_dir, 224, 224)
import numpy as np import time from keras.models import load_model from keras.utils.generic_utils import CustomObjectScope import keras from util.dataset import get_files test_dir = '/home/pdd/pdwork/CV_BiShe/picture/trainTest/' test, test_label = get_files(test_dir, 224, 224) def test_model(test, test_label, model_name): #test_dir= '/home/pdd/pdwork/CV_BiShe/picture/picValidation/' TP = 0 TN = 0 FP = 0 FN = 0 if (model_name[-3:] != '.h5'): model_name += '.h5' with CustomObjectScope({ 'relu6': keras.applications.mobilenet.relu6, 'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D }): model = load_model(model_name) #('DenseDWNet.h5') time_start = time.time() test_result = model.predict(test) time_end = time.time()
test_result = model.predict(test) time_end = time.time() time_spent = time_end - time_start print(time_spent) #calc precision and recall for i in range(0, len(test_label)): if np.argmax(test_result[i]) == 1: if np.argmax(test_label[i]) == 1: TP += 1 else: FP += 1 else: if np.argmax(test_label[i]) == 1: FN += 1 else: TN += 1 print(TP, TN, FP, FN) precision = TP / (FP + TP) recall = TP / (FN + TP) print('precision', precision) print('recall', recall) return time_spent, precision, recall #train_dir ="/home/pdd/pdwork/CV_BiShe/picture/picTrain" train_dir = "/home/pdd/pdwork/CV_BiShe/picture/trainTest" train, train_label = get_files(train_dir, 227, 227) train_alexnet(train, train_label)
from model.mobilenet_v2 import MobileNetv2 from model.proposed import DenseDWNet import matplotlib.pyplot as plt from util.dataset import get_files from keras.callbacks import ReduceLROnPlateau, CSVLogger, TensorBoard, ModelCheckpoint, LearningRateScheduler from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img train_dir = "/home/pdd/pdwork/CV_BiShe/picture/picTrain" #train_dir ="/home/pdd/pdwork/CV_BiShe/picture/picTrain" x_train, y_train = get_files(train_dir, 224, 224) validation_dir = "/home/pdd/pdwork/CV_BiShe/picture/picValidation" x_test, y_test = get_files(train_dir, 224, 224) #model = MobileNetv2((224, 224, 3), 2) model = DenseDWNet((224, 224, 3), 2) model.compile(loss="categorical_crossentropy", optimizer='sgd', metrics=['accuracy']) log = CSVLogger('result/log_epoch.csv', separator=',', append=False) board = TensorBoard(log_dir='result/logs', histogram_freq=0, write_graph=True, write_images=False, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None) filepath = "model_{epoch:02d}-{val_acc:.2f}.h5" checkpoint = ModelCheckpoint(filepath, monitor='val_acc',