<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 CNN Example
Step1:  Importing all the data
Step2:  Visualizing some examples
Step3:  The hyperparameters of the model are
Step4:  Now, training the model using 10001 steps
Step5:  Cheking the trained model with the test dataset
Step6:  Seeing the model perform in 9 images from the valid dataset
<ASSISTANT_TASK:>
Python Code:
import os
import sys
import tensorflow as tf
import inspect
import matplotlib.pyplot as plt
import numpy as np
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
from util import get_data_4d, plot9images,randomize_in_place
from CNN import CNNModel, train_model,check_test,one_prediction
from DataHolder import DataHolder
from Config import Config
Explanation: CNN Example: notMNIST dataset
The notMNIST dataset is a example similar to MNIST. The data consists of characters rendered in a variety of fonts on a 28x28 image. The labels are limited to 'A' through 'J' (10 classes).
End of explanation
train_dataset, train_labels, valid_dataset, valid_labels, test_dataset, test_labels = get_data_4d()
print('Training:', train_dataset.shape, train_labels.shape)
print('Validation:', valid_dataset.shape, valid_labels.shape)
print('Testing:', test_dataset.shape, test_labels.shape)
Explanation: Importing all the data
End of explanation
train_classes = np.argmax(train_labels, axis=1)
train_classes = [chr(i + ord('A')) for i in train_classes]
img_size = 28
img_shape = (img_size, img_size)
images = train_dataset[0:9]
cls_true = train_classes[0:9]
plot9images(images, cls_true, img_shape)  
Explanation: Visualizing some examples
End of explanation
my_config = Config()
print("batch_size = {}".format(my_config.batch_size))
print("patch_size = {}".format(my_config.patch_size))
print("image_size = {}".format(my_config.image_size))
print("num_labels = {}".format(my_config.num_labels))
print("num_channels = {}".format(my_config.num_channels))
print("num_filters_1 = {}".format(my_config.num_filters_1))
print("num_filters_2 = {}".format(my_config.num_filters_2))
print("hidden_nodes_1 = {}".format(my_config.hidden_nodes_1))
print("hidden_nodes_2 = {}".format(my_config.hidden_nodes_2))
print("hidden_nodes_3 = {}".format(my_config.hidden_nodes_3))
print("learning_rate = {}".format(my_config.learning_rate))
print("steps_for_decay = {}".format(my_config.steps_for_decay))
print("decay_rate = {}".format(my_config.decay_rate))
Explanation: The hyperparameters of the model are
End of explanation
my_dataholder = DataHolder(train_dataset,
                           train_labels,
                           valid_dataset,
                           valid_labels,
                           test_dataset,
                           test_labels)
my_model = CNNModel(my_config, my_dataholder)
train_model(my_model, my_dataholder, num_steps=10001, show_step=1000)
Explanation: Now, training the model using 10001 steps
End of explanation
print("Test accuracy: %.2f%%" % (check_test(my_model) * 100))
Explanation: Cheking the trained model with the test dataset
End of explanation
randomize_in_place(valid_dataset, valid_labels, 0)
valid_classes = np.argmax(valid_labels, axis=1)
valid_classes = [chr(i + ord('A')) for i in valid_classes]
cls_true = valid_classes[0:9]
images = valid_dataset[0:9]
images = [image.reshape(1,
                        image.shape[0],
                        image.shape[1],
                        image.shape[2]) for image in images]
predictions = [chr(one_prediction(my_model, image) + ord('A')) for image in images]
plot9images(images, cls_true, img_shape)  
Explanation: Seeing the model perform in 9 images from the valid dataset
End of explanation
<END_TASK>