<jupyter_start><jupyter_text>Test our trained modelLoad the trained model and look at how well it performs<jupyter_code>%load_ext autoreload
%autoreload 2

import sys
sys.path.append('../')

import scipy.misc
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
from model.model import cnn
from data import generators 

image_size = (78, 227, 3)<jupyter_output>The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload<jupyter_text>* Start by loading the pre-trained model weights<jupyter_code>saved_model = '../logs/weights-2018-11-02-11-00-18.hdf5'
model = cnn(input_shape=image_size)
model.load_weights(saved_model)<jupyter_output>cnn(): Creating CNN with parameters:

input_shape=(78, 227, 3)
kernel_size=(3, 3)
pool_size=(2, 2)
dropout=0.5
activation=elu
optimizer=<keras.optimizers.Adam object at 0x7fbaccc65f28>
loss=mean_squared_error<jupyter_text>* Prepare our test dataThis is the same approach we used to create train and validation data sets previously<jupyter_code>columns = ['image_name', 'angle', 'date', 'time']
df = pd.read_csv('../data/data.txt', names=columns, delimiter=' ')

sample_idx = {}
num_samples = len(df)
sample_idx['train'] = [i for i in range(0, num_samples, 2)]
sample_idx['valid'] = [i for i in range(1, num_samples, 4)]
sample_idx['test'] = [i for i in range(3, num_samples, 4)]<jupyter_output><empty_output><jupyter_text>* Create a generator for test data<jupyter_code>test_generator = generators.DataGenerator(df.loc[sample_idx['test']],
                                           data_dir='../data/data',
                                           image_size=image_size,
                                           label='Test')
predicted_angles = pd.DataFrame(model.predict_generator(test_generator, verbose=1)<jupyter_output>498/498 [==============================] - 141s 283ms/step<jupyter_text>* Created a dataframe with predicted and actual steering angles<jupyter_code>df_predict = pd.DataFrame(predicted_angles, columns=['predicted'])
df_predict['actual'] = df.loc[sample_idx['test']]['angle']  \
        .values[:len(df_predict['predicted'])] * scipy.pi / 180
df_predict['diff'] = df_predict['predicted'] - df_predict['actual']<jupyter_output><empty_output><jupyter_text>* Graph the results<jupyter_code>plt.plot(df_predict['actual'], color='green')
plt.plot(df_predict['predicted'], color='red')
plt.show()
plt.plot(df_predict['diff'])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1408906882591093, 'fraction_numerical': 0.025101214574898785, 'mean_word_length': 5.13151364764268, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '413522', 'license': 'MIT', 'n_tokens_mistral': 872, 'n_tokens_neox': 807, 'n_words': 180, 'path': '4. Predicting the steering angle of a car/Source/notebooks/test-trained-model.ipynb', 'repo_name': 'PacktPublishing/Learning-Python-Artificial-Intelligence-by-Example', 'size': '2470'}