if __name__ == '__main__':
    # wrap Flask application with socketio's middleware
    app = socketio.Middleware(sio, app)

    parser = argparse.ArgumentParser()

    parser.add_argument('weight_file',
                        help='The model file to use for inference')


    parser.add_argument('--pred_viz',
                        action='store_true',
                        help='display live overlay visualization with prediction regions')

    args = parser.parse_args()

    model = model_tools.load_network(args.weight_file)
    image_hw = model.layers[0].output_shape[1]

    if args.pred_viz: 
        overlay_plot = visualization.SideBySidePlot('Segmentation Overlay', image_hw)
        queue = overlay_plot.start()
    else:
        queue = None

    follower = Follower(image_hw, model, args.pred_viz, queue)
    # start eventlet server
    
    sio_server()
Exemple #2
0
# ## Prediction <a id='prediction'></a>
#
# Now that you have your model trained and saved, you can make predictions on your validation dataset. These predictions can be compared to the mask images, which are the ground truth labels, to evaluate how well your model is doing under different conditions.
#
# There are three different predictions available from the helper code provided:
# - **patrol_with_targ**: Test how well the network can detect the hero from a distance.
# - **patrol_non_targ**: Test how often the network makes a mistake and identifies the wrong person as the target.
# - **following_images**: Test how well the network can identify the target while following them.

# In[13]:

# If you need to load a model which you previously trained you can uncomment the codeline that calls the function below.

weight_file_name = 'model_weights'
restored_model = model_tools.load_network(weight_file_name)

# The following cell will write predictions to files and return paths to the appropriate directories.
# The `run_num` parameter is used to define or group all the data for a particular model run. You can change it for different runs. For example, 'run_1', 'run_2' etc.

# In[14]:

run_num = 'run_2'

val_with_targ, pred_with_targ = model_tools.write_predictions_grade_set(
    model, run_num, 'patrol_with_targ', 'sample_evaluation_data')

val_no_targ, pred_no_targ = model_tools.write_predictions_grade_set(
    model, run_num, 'patrol_non_targ', 'sample_evaluation_data')

val_following, pred_following = model_tools.write_predictions_grade_set(
 def load_model(self, weight_file_name):
     #loads weight file located at ../data/weights/
     #returns corresponding model
     print('Loading model...')
     model = model_tools.load_network(weight_file_name)
     return model
 # Call fcn_model()
 output_layer = fcn_model(inputs, num_classes, depth_, keepProb)
 
 # Define the Keras model and compile it for training
 model = models.Model(inputs=inputs, outputs=output_layer)
 
 
 
 
 # Load latest model for retraining
 # that will not work only in windows
 
 list_of_files = glob.glob('../data/weights/*') # * means all if need specific format then *.csv
 weight_file_name =  max(list_of_files, key=os.path.getctime)
 weight_file_name = weight_file_name.split("\\")
 model = model_tools.load_network(weight_file_name[-1])
 
 # if you are not on windows, copy name of the model
 # from 'weights' folder and uncomment
 
 #model = model_tools.load_network('your_model_name')
 
 # Compile
 model.compile(optimizer=keras.optimizers.Adam(learning_rate), loss='categorical_crossentropy')
 
 # Current best score
 s = weight_file_name[-1].split('_')
 fg = float(s[0]) 
 arr=[]
 
 # To change evaluation pipeline
    # wrap Flask application with socketio's middleware
    print ("Starting...")
    app = socketio.Middleware(sio, app)

    print ("Parsing cmd-line arguments...")
    parser = argparse.ArgumentParser()
    parser.add_argument('arch_file',
                        help='The model architecture (.json) file for loading the model')
    parser.add_argument('weights_file',
                        help='The model weights (.hd5) file to use for inference')
    parser.add_argument('--pred_viz',
                        action='store_true',
                        help='display live overlay visualization with prediction regions')
    args = parser.parse_args()
    
    print ("Loading the model...")
    model = model_tools.load_network(args.arch_file, args.weights_file)
    image_hw = model.layers[0].output_shape[1]

    if args.pred_viz: 
        overlay_plot = visualization.SideBySidePlot('Segmentation Overlay', image_hw)
        queue = overlay_plot.start()
    else:
        queue = None

    print ("Creating the follower...")
    follower = Follower(image_hw, model, args.pred_viz, queue)
    # start eventlet server
    
    sio_server()
from utils import model_tools

from tensorflow.contrib.keras.python import keras
from tensorflow.contrib.keras.python.keras import layers, models

from utils.separable_conv2d import SeparableConv2DKeras, BilinearUpSampling2D
from utils import data_iterator
from utils import plotting_tools 
from utils import model_tools

from datetime import datetime
from utils import scoring_utils

### Test on Pics ####

model = model_tools.load_network('0.49256118836_model_23_25_04_10_2017.h5')

'''
# This part did not work for reviewer, windows only
# config is uploaded instead of the model
# works for me though

list_of_files = glob.glob('../data/weights/*') # * means all if need specific format then *.csv
# Last created file
weight_file_name =  max(list_of_files, key=os.path.getctime)
weight_file_name = weight_file_name.split("\\")


if 'config' in weight_file_name[-1]:
    model = model_tools.load_network(weight_file_name[-2])
else:
if __name__ == '__main__':
    # wrap Flask application with socketio's middleware
    app = socketio.Middleware(sio, app)

    parser = argparse.ArgumentParser()

    parser.add_argument('weight_file',
                        help='The model file to use for inference')


    parser.add_argument('--pred_viz',
                        action='store_true',
                        help='display live overlay visualization with prediction regions')

    args = parser.parse_args()

    model = model_tools.load_network(args.weight_file)
    image_hw = model.layers[0].output_shape[1]

    if args.pred_viz: 
        overlay_plot = visualization.SideBySidePlot('Segmentation Overlay', image_hw)
        queue = overlay_plot.start()
    else:
        queue = None

    follower = Follower(image_hw, model, args.pred_viz, queue)
    # start eventlet server
    
    sio_server()