<jupyter_start><jupyter_text>Load the neural network and make predictions<jupyter_code># import sys so we can use packages outside of this folder in
# either python 2 or python 3
import sys
sys.path.insert(0,'..')

#import other useful libraries
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.python.keras.models import load_model
from preprocessing.utils import ImageUtils
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
import tensorflow.keras.backend as K  
%matplotlib inline
imgs= np.asarray(imgs).astype('float')
commands = np.asarray(commands)

#load the image utils
iu=ImageUtils()

# define the model 
MODEL = '../models/daev_accuracy.hdf5'
BATCH_SIZE =64 

# the model was trained with the custom metric so need to define it
def customAccuracy(y_true, y_pred):
    diff = K.abs(y_true-y_pred) #absolute difference between correct and predicted values
    correct = K.less(diff,0.01) #tensor with 0 for false values and 1 for true values
    return K.mean(correct) #sum all 1's and divide by the total. 


# load the model 
model=load_model(MODEL,custom_objects={'customAccuracy': customAccuracy})

#get the height and width from the model so we don't get annoying errors
height= model.layers[0].input_shape[1]
width =  model.layers[0].input_shape[2]

# normalize the imgs,reshape them, and normalize the commands
normalized_imgs=[]
commands = commands /0.6108652353
for img in imgs:
    img = img/255.0
    img=iu.reshape_image(img,height,width)
    normalized_imgs.append(img)
    
normalized_imgs=np.asarray(normalized_imgs)

# make the predictions 

predictions = model.predict(normalized_imgs, batch_size=BATCH_SIZE,verbose=1) 

acc=np.mean((commands-predictions)<0.01)
print("Accuracy: {}".format(acc))<jupyter_output>2036/2036 [==============================] - 1s 417us/sample
Accuracy: 0.535530152732<jupyter_text>Plot the Results<jupyter_code>plt.figure()

plt.plot(np.arange(0,len(commands)),commands,label='commands')
plt.plot(np.arange(0,len(commands)),predictions,label='predictions')
plt.title("Predictions vs Ground Truth")
plt.xlabel("Time Step")
plt.ylabel("Normalized Steering Command (radians)")
plt.legend()
plt.show()
plt.figure()
diff= commands.flatten() - predictions.flatten()
plt.plot(np.arange(0,len(commands)),abs(diff))
plt.title("Absolute difference Between Prediction and Ground Truth")
plt.xlabel("Time Step")
plt.ylabel("command-pred")
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12015655577299413, 'fraction_numerical': 0.024657534246575342, 'mean_word_length': 6.159663865546219, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '654360', 'license': 'MIT', 'n_tokens_mistral': 888, 'n_tokens_neox': 825, 'n_words': 220, 'path': 'src/computer_vision/notebooks/Evaluate_e2e_bag.ipynb', 'repo_name': 'mldiego/Platooning-F1Tenth', 'size': '2555'}