def train48Net(X,Y,W, windowSize=48, batchSize=16, nbEpoch=10): #Load model architecture modelFileName = '48_trained_model_w' + str(windowSize) + '_batch' + str(batchSize) +'.h5' model = model_architecture.setUp48net(windowSize) if (os.path.exists(os.getcwd()+'/' + modelFileName)): model.load_weights(modelFileName) print("Loaded model: " + modelFileName) else: print("No model stored, creating new") print("======Training....======") history = model.fit(X, Y, batch_size=batchSize, nb_epoch=nbEpoch, verbose=1) print("Finished training!") model.save_weights(modelFileName, overwrite=True) print("saved model to: " + modelFileName) return history
def train48Net(X, Y, W, windowSize=48, batchSize=16, nbEpoch=10): #Load model architecture modelFileName = '48_trained_model_w' + str(windowSize) + '_batch' + str( batchSize) + '.h5' model = model_architecture.setUp48net(windowSize) if (os.path.exists(os.getcwd() + '/' + modelFileName)): model.load_weights(modelFileName) print("Loaded model: " + modelFileName) else: print("No model stored, creating new") print("======Training....======") history = model.fit(X, Y, batch_size=batchSize, nb_epoch=nbEpoch, verbose=1) print("Finished training!") model.save_weights(modelFileName, overwrite=True) print("saved model to: " + modelFileName) return history
print("Image database: {0} images".format(len(imdb))) [X, Y, W] = il.getCNNFormat(imdb, stepSize, windowSize) print("finished preprocessing in {0}".format(time.time() - start_time)) print("=========================================") #================================================ # 12 net #================================================ print("\n\n============== 12Net ====================") model12 = model_architecture.setUp12net(windowSize) print("Loading model from: " + model12FileName) model12.load_weights(model12FileName) model48 = model_architecture.setUp48net(windowSize48) print("Loading model from: " + model48FileName) model48.load_weights(model48FileName) # Get best predictions start_time = time.time() predictions_12 = model12.predict(X, batch_size=16, verbose=1) # Get top 10% targets = np.squeeze(predictions_12) nb_top_targets = int(math.ceil(targets.shape[0] * 0.1)) p_idx = np.argsort(targets)[-nb_top_targets:] predictions_12 = predictions_12[p_idx, :] Y = Y[p_idx, :] X = X[p_idx, :, :, :] W = W[p_idx, :, :]
print("Image database: {0} images".format(len(imdb))) [X, Y, W] = il.getCNNFormat(imdb, stepSize, windowSize) print("finished preprocessing in {0}".format(time.time()-start_time)) print("=========================================") #================================================ # 12 net #================================================ print("\n\n============== 12Net ====================") model12 = model_architecture.setUp12net(windowSize) print("Loading model from: " + model12FileName) model12.load_weights(model12FileName) model48 = model_architecture.setUp48net(windowSize48) print("Loading model from: " + model48FileName) model48.load_weights(model48FileName) # Get best predictions start_time = time.time() predictions_12 = model12.predict(X, batch_size=16, verbose=1) # Get top 10% targets = np.squeeze(predictions_12) nb_top_targets = int(math.ceil(targets.shape[0]*0.1)) p_idx = np.argsort(targets)[-nb_top_targets:] #==================Pick out high indices============= predictions_high = []