Highlights
Task:
Itroduction In this project, we are going to study how to use TensorFlow Keras to build a convolutional neural network (CNN) from scratch for doing image classification tasks. Your main task is to write a notebook on the Google Colab platform. We have provided a starter notebook to help you get started. In the notebook, there are several sections. In the "Image Classifier Code" section, you will find a class called ImageClassifier with some skeleton code. You are to implements the class according to the specification below. This class can be reused for classifying images of different datasets. Suppose that we have three image datasets. We can create three objects of ImageClassifier and associate each of them to the corresponding dataset. Then we can train each classifier with a training set and test its accuracy against a testing set. Assumptions • We will process RGB images of 8-bit color depth only. • Assume that the number of label classes is about 10 or fewer. Program Design Specification (1) Data Preprocessing preprocess(ds, img_height, img_width, batch_size=32, shuffle=True) This function is mainly used to resize the images from a dataset (ds) into the specified height and width (img_height and img_width) which form the input shape expected by the neural network. This function also wraps the dataset object (ds) into one that returns images as batches and enables features for performance or training accuracy improvement: • Dataset.batch() combines consecutive elements of this dataset into batches. Use the batch_size argument passed in for this method call. • Dataset.shuffle() randomly shuffles the elements of this dataset, and should be called if the shuffle argument is True. This can result in better training accuracy. Note that you should use a large value like 1000 or 10000 for the buffer size for the shuffle() call instead of 32 here. • Dataset.prefetch() overlaps data preprocessing and model execution while training. Prefetching should always be enabled. Let the system decided on a right buffer size to prefetch by using the constant tf.data.experimental.AUTOTUNE. See performance tips or the flowers example notebook to know more. (2) Constructor __init__(self, train_ds, test_ds, metadata, img_height, img_width, img_depth=3, batch_size=32, shuffle=True, augment=False, dropout=False) Constructs the ImageClassifier instance. It has references to the training dataset train_ds and the testing dataset test_ds objects. It calls the preprocess() function passing to it the img_height, img_width, batch_size and shuffle arguments to perform data preprocessing before training the the CNN. The preprocessed datasets are saved as attributes train_pds and train_pds respectively for ease of use later. AIST1110 Introduction to Computing Using Python 2020-21
Term 1 Department of Computer Science and Engineering, The Chinese University of Hong Kong 2 If the augment parameter is True, add a data augmentation layer to the CNN to apply random effects like horizontal flip, rotation, zooming or cropping, contrast, width or height variation, etc. on the input images. Refer to the documentation of the tf.keras.layers.experimental.preprocessing module to know what effects can be applied. There is no specific requirement on the choices and how many of the effects should be included. You should experiment somehow (e.g. how much to rotate). But we suggest using at least three of them to ensure more variations on your input images. This can help combat the overfitting problem in the training process. If the dropout parameter is True, add a Dropout layer to your CNN. The range for the dropout value should not be more than 0.5. You can set it to 0.5 for the best effect to avoid overfitting. Then the most important step is to create your CNN model and compile it. There is no specific requirement on the network configuration. You can compose any of the following layers or others. Not all of them are required, depending on your design of the network. For example, some people may like to take the softmax() operation on the network output only when doing predictions, then you need not use the Softmax layer as the final layer in your network.
• tf.keras.Input • tf.keras.layers.Conv2D
• tf.keras.layers.MaxPooling2D •
tf.keras.layers.Flatten
• tf.keras.layers.Softmax Remember that your input image data are integers in the range [0, 255]. You should "normalize" them into small floating-point values. One common way to do so is to divide each element by 255. Also note that the following layer can help do this for you.
• tf.keras.layers.experimental.preprocessing.Rescaling Other ways of normalization are also welcome if you love to explore. When compiling the model, the optimizer or loss function to use are also up to you. Nowadays, people love to use Adam. For the loss function, you may refer to the flowers example notebook.
(3) Training train(self, epochs=15) This function is to fit the created model, i.e. starts the training. The common way is to call the fit() method on the model, which returns a history object that records the accuracy and loss variation data that can be plotted. We assign the history object and epochs as attributes for easy reference from another method.
(4) Evaluation evaluate(self, test_ds=None) This function is to evaluate the trained model against an input test dataset, which can be passed from the outside. The default is None – in this case, we use the preprocessed test dataset that has been set up during ImageClassifier construction. The coding for function has been done for you.
(5) Learning Curve Plots plot_learning_curve(self) AIST1110 Introduction to Computing Using Python 2020-21 Term 1 Department of Computer Science and Engineering, The Chinese University of Hong Kong 3 This function is to plot the accuracy and loss variation during the training and validation phases as a figure of two subplots. The exact size and styles of figure are unimportant. However, titles and legends must be shown.
(6) Confusion Matrix print_confusion_matrix(self, test_ds=None, alt_label=False) This function is to print the confusion matrix to show how well the CNN predicts for a test dataset. Again, the dataset can be passed from outside. The default is None, then we will use the preprocessed test dataset that has been set up during ImageClassifier construction.
This AIST1110 : IT Assignment has been solved by our IT Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.