STEP_SIZE_TRAIN = train_generator.__len__() STEP_SIZE_VALID = validation_generator.__len__() # Set new model name. model_name = 'headpose' + str(int(time.time())) model_path = model_dir + model_name + '.h5' loss_csv = model_dir + model_name + '_loss.csv' # Configure a callback for logging train progress in a .csv file. csv_logger = CSVLogger(loss_csv) # Configure estimator model from architecture parameters set before. model = mpatacchiola_generic(in_size, num_conv_blocks, num_filters_start, num_dense_layers, dense_layer_size, dropout_rate) model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mae']) # Train the configured model on the train generator. history = model.fit_generator(generator=train_generator, steps_per_epoch=STEP_SIZE_TRAIN, validation_data=validation_generator, validation_steps=STEP_SIZE_VALID, epochs=epochs, callbacks=[reduce_lr, stop, csv_logger], verbose=verbose) # Get score for the dataset (tilt, pan and global error). pred = model.predict((test_array / 255.0 - mean) / std)
mean = 0.408808 std = 0.237583 t_mean = -0.041212 t_std = 0.323931 p_mean = -0.000276 p_std = 0.540958 # Models. head_detector = ssd_512(image_size=(in_size_detector, in_size_detector, 3), n_classes=1, min_scale=0.1, max_scale=1, mode='inference') head_detector.load_weights(detector_path) pose_estimator = mpatacchiola_generic(in_size_estimator, num_conv_blocks, num_filters_start, num_dense_layers, dense_layer_size) pose_estimator.load_weights(estimator_path) # Get video source. video_source = input("Input stream: ") # If video source is a device convert the string identifying it to integer. try: video_source = int(video_source) except: pass # Initialize cam.