<jupyter_start><jupyter_text>Import MNIST Dataset<jupyter_code>from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", reshape = False, one_hot=True)
numTest = mnist.test.images.shape[0]
testData = mnist.test.images[:numTest,:]
testLabels = mnist.test.labels[:numTest,:]
print("Number of test examples = ", numTest)
print("Test Data shape = ", testData.shape)
print("Test Data labels shape = ", testLabels.shape)<jupyter_output>Number of test examples =  10000
Test Data shape =  (10000, 28, 28, 1)
Test Data labels shape =  (10000, 10)<jupyter_text>Importing the int8 precision model and float32 model and measuring latency<jupyter_code>interpreter = tf.lite.Interpreter(model_path="C://users/navee/Quantized_int8_model.tflite")
interpreter.allocate_tensors()
input_index = interpreter.get_input_details()[0]["index"]
start = time.time()
count = 0
for i in range(numTest):
    input_data = np.array(testData[i].reshape([1, 784]), dtype = np.float32)
    interpreter.set_tensor(input_index, input_data)
    interpreter.invoke()
    output_details = interpreter.get_output_details()
    output_index = output_details[0]['index']
    output_data = interpreter.get_tensor(output_index)
    pred_model = np.argmax(output_data)
    pred_data = np.argmax(testLabels[i])
    if(pred_model == pred_data):
        count += 1
end = time.time()
print("Inference Time = ", end - start)
print("Accuracy = ", str((count / numTest) * 100))
interpreter = tf.lite.Interpreter(model_path="C://users/navee/FullPrecision_float32_model.tflite")
interpreter.allocate_tensors()
input_index = interpreter.get_input_details()[0]["index"]
start = time.time()
count = 0
for i in range(numTest):
    input_data = np.array(testData[i].reshape([1, 784]), dtype = np.float32)
    interpreter.set_tensor(input_index, input_data)
    interpreter.invoke()
    output_details = interpreter.get_output_details()
    output_index = output_details[0]['index']
    output_data = interpreter.get_tensor(output_index)
    pred_model = np.argmax(output_data)
    pred_data = np.argmax(testLabels[i])
    if(pred_model == pred_data):
        count += 1
end = time.time()
print("Inference Time = ", end - start) 
print("Accuracy = ", str((count / numTest) * 100))<jupyter_output>Accuracy = 96.49
{'fraction_non_alphanumeric': 0.13330438558402083, 'fraction_numerical': 0.025618758141554496, 'mean_word_length': 5.47191011235955, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '583376', 'license': 'MIT', 'n_tokens_mistral': 840, 'n_tokens_neox': 785, 'n_words': 148, 'path': 'Quantization/MNIST/LeNet-300-100/Inferences_FP32_INT8_Models_LeNet-300-100.ipynb', 'repo_name': 'Naveen-Lalwani/18663-Study-of-Neural-Network-Compression-Techniques', 'size': '2303'}