save_best_only=True), tensorboard, EarlyStopping(monitor='val_loss', patience=5, verbose=1) ] print('=> created callback objects <=') print('=> initializing training loop <=') history = model.fit_generator(train_generator, steps_per_epoch=train_steps, epochs=epochs, validation_data=validation_generator, validation_steps=val_steps, workers=8, use_multiprocessing=True, max_queue_size=500, callbacks=callbacks_list) print('=> loading best weights <=') model.load_weights(final_weights_path) print('=> saving final model <=') pmodel.save( os.path.join(os.path.abspath(model_path), 'Weights/model_InceptionResnetV2_15Layer.h5')) #Load-Model #Not Required #Comment Out All Lines When Required #new_model=tf.keras.models.load_model('/home/jediyoda/Maharshi/Coffee-Table-Material/Weights/model_InceptionResnetV2_1Layer.h5') #new_model.summary() #Predictions predictions = [] img_path = Changes_To_Be_Made.Image_Path #Set This To The Val Directory Path CSV_Name = Changes_To_Be_Made.Csv_Name #Set CSV Name To Be Generated
# Running the model history = model.fit_generator(train_generator, steps_per_epoch=train_steps, epochs=epochs, validation_data=validation_generator, validation_steps=val_steps, workers=2, use_multiprocessing=False, max_queue_size=500, callbacks=callbacks_list) filepath = os.path.join(os.path.abspath(model_path), 'Weights/top_model_weights_' + 'Frozen_Layers.h5') print('=> loading best weights <=') model.load_weights(filepath) print('=> saving final model <=') Final_Weights = 'Weights/model_' + architecture_name + "_" + str( layers_frozen) + 'Frozen_Layers.h5' pmodel.save(os.path.join(os.path.abspath(model_path), Final_Weights)) # These steps are only for checking predictions and only needed # to run if you need to check predictions on your data # Loading the model with best weights new_model = tf.keras.models.load_model(filepath) #new_model.summary() #Predictions
import cv2 from keras.models import Sequential from keras.models import load_weights from keras.layers import Convolution2D, MaxPooling2D from keras.layers import Activation, Dropout, Flatten, Dense import h5py import numpy as np categories = ['chair', 'elephant', 'camera', 'flamingo', 'butterfly'] nb_classes = len(categories) model = load_weights('./5obj-model.hdf5') data_dir = './data/' image_w = 64 image_h = 64 pixels = image_w * image_h * 3 img = cv2.imread('./data/butterfly/00000.jpg') img = cv2.resize(img, (image_w, image_h)) predict = model.predict([img]) print(predict) name = categories[pre[0].argmax()] save_dir = './data/' + name os.makedirs(save_dir, exist_ok=True)
import pandas as pd import re import os import tensorflow as tf from numpy import array import keras from keras.layers import Input, Lambda, Dense from keras.models import Model import keras.backend as K from keras.preprocessing import sequence from keras.models import load_model, load_weights app = Flask(__name__) MODEL_PATH = '/home/akhil/Downloads/deep_learning/elmo/elmo_model.h5' model = load_weights(MODEL_PATH) @app.route('/') def home(): return render_template('index.html') @app.route('/predict', methods=['POST']) def predict(): if request.method == 'POST': message = request.form['message'] data = [message] vect = model.transform(data).toarray() my_prediction = classifier.predict(vect) return render_template('result.html', prediction=my_prediction) if __name__ == '__main__':
#coding=utf8 import keras from keras.models import load_weights model = load_weights('/home/smallchild/keras-yolo3/model_data/trained_weights_final.h5') model.summary()