DAY 5: CNN TRANSFER LEARNING

CNN Transfer Learning with TensorFlow Hub sample code for my project:

The next step is to adapt this to GNN, which may be very challenging because it is not yet compatible.

Over the weekend, I also tested what would happen if I took two photos from s123450 and incorrectly put their photos in the s123451 folder to see how much the accuracy would go down/how many epochs it takes.

It took a few seconds longer, but the accuracy was still at 100%. I tested a larger “incorrect dataset” with 12 images, but it still eventually got to 100% in the first epoch. Since the dataset is so large for each folder of photos, switching out a few didn’t make a different.

DAY 4: OPEN JIRAS

To expand my dataset, I took more student videos with the security robot’s webcam and also took non-student videos to develop “negative” data. I processed these videos into still images and converted/resized the new photos. Then, I was able to test the TensorFlow model with a full dataset (positive and negative data) to achieve these results:

The re-trained model correctly identified students (s12345#) and non-students (x#).

Next, I tested/ran the HPCC GNN Model and sprayed animal data to HPCC.

After training the 80×80 images on the GNN model, this was the result:

The accuracy level was extremely low (around 18%). I continued on to test the student images in the GNN model (instead of animal images) to see how the accuracy result would compare.

Ultimately, the run failed. I opened a Jira for this issue.

The error message says that the index was out of range. I ran it again with the image size classified as 76×76 (although the actual image size was still 80×80) to see if it would change the results. After 25 minutes, the model failed to run. I opened another Jira with the details of this second attempt.

DAY 4: MIDTERM – END PLAN

References

  1. Transfer Learning with TensorFlow Hub Tutorials https://www.tensorflow.org/tutorials/images/transfer_learning_with_hub
  2. MobileNet V2 (Lightweight models for use in mobile application): https://arxiv.org/pdf/1801.04381.pdf 
  3. Hands-on Machine Learning with Scikit-Learn, Keras, & TensorFlow
    1. Chapter 14
  4. TensorFlow Keras API: https://www.tensorflow.org/api_docs/python/tf/ 
  5. TensorFlow Hub API: https://www.tensorflow.org/hub/api_docs/python/hub 

Training Image Data with GNN

  • Image classification
    • Categories: 
      • AHS students/staff or Not AHS students/staff
      • Graduation year (Class-2022)
    • Each group’s images can be saved in a directory. The directory name is labeled as the category’s name
      • Formatted for TensorFlow Hub (JPG, BMP, PNG, etc).
    • Put all image files in a single directory with file format
      • <purpose>-<id>-index-<category name>.bmp
        • Must be bmp since this step is for GNN
      • <purpose> will be: 
        • T: Training
        • V: Validation
        • P: Predication

Prepare Image Files

  • Size: 224×224 with 3 channels (red, blue, green)
  • Save the image file in <purpose>-<id>-index-<category name>.bmp
  • 80% for training, 15% for validation, 5% for prediction
  • Around 2,000 – 3,000 image files

Spray Image Data to HPCC Cluster

  • Spray through ECL Watch as Blob data type

Use GNN Tutorial model (or a similar alternative)

  • Two categories: AHS or Not_AHS

Use MobileNet V2 Model

  1. In a ECL embedded Python module
    1. Feature_extractor_model = “https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4” 
    2. feature_extractor_layer = hub.KerasLayer(

    feature_extractor_model, input_shape=(224, 224, 3), trainable=False)

  1. feature_batch = feature_extractor_layer(image_batch)  image_batch will be in the shape of (32, 224, 224, 3). The first “32” is the batch Size
  2. save the feature_extraor_layer in json string
  1. In a ECL module
    1. Create sequential model with input Tensor, feature_extraor_layer json and output KerasLayer
    2. compile model
    3. train the model
    4. validate and predict
    5. Output loss and accuracy,etc
    6. Save the model in JSON string
    7. Save the weights in JSON string
  2. In a ECL Embedded Python Module
    1. Restore the model with the model JSON and weights JSON.
    2. Output model information to the verify
    3. Convert the model to TensorFlow lite
    4. Save both original model and lite model 

If I am unable to use the pretrained MobileNet V2 model, I will try to manually create it or use something similar

  • Reference 3) page 497 
    • Introduction to build a ResNet-34 model
    • Follow the layout there
  • Code: 

model = keras.models.Sequential() 

model.add( keras.layers.Conv2D( 64, 7, strides = 2, input_shape =[ 224, 224, 3], padding =” same”, use_bias = False)) 

model.add( keras.layers.BatchNormalization()) 

model.add( keras.layers.Activation(” relu”)) 

model.add( keras.layers.MaxPool2D( pool_size = 3, strides = 2, padding =” same”)) 

prev_filters = 64 

for filters in [64] * 3 + [128] * 4 + [256] * 6 + [512] * 3: 

  strides = 1 if filters = = prev_filters else 2 model.add( ResidualUnit( filters, strides = strides)) prev_filters = filters 

  model.add( keras.layers.GlobalAvgPool2D()) 

  model.add( keras.layers.Flatten()) 

  model.add( keras.layers.Dense( 2, activation =” softmax”))

This is not ideal since there are many filters to be created and added, but it is a valid backup plan.

DAYS 2+3: GNN MODEL

I am currently trying to create a model similar to the one in the GNN Tutorial using 12 student bmp files. Each image is 80×80 with 3 colors. When attempting to train the model, the process never finished.

Thor Slave Log
ECL Watch

System Error

I’m in the process of troubleshooting this error message to run my images using the model and achieve a higher accuracy.

DAY 1: HPCC GNN PHOTOS

Today I ran the HPCC tutorial images on my Jupyter Notebook pre-trained model (https://www.tensorflow.org/tutorials/images/transfer_learning_with_hub).

After resizing the animal images to 224 x 224, I created two folders (“dog” and “not dog”) to classify the images.

Upon running the model, I received a “SavedModel does not exist” error message.

To troubleshoot, I referred to forums that suggested to delete the path the error was referring to (https://github.com/tensorflow/hub/issues/646). The final solution that fixed my error message was simply rebooting my computer.

I ran the model with 3 epochs and received this result:

Results after 5 epochs:

Accuracy after 5 epochs

The model achieved 100% accuracy on the fourth epoch.

The ImageNet predictions before training the model produced these results:

The labels are supposed to be incorrect because these animals aren’t in the dataset yet.

After training the model, these are the model predictions:

The model’s predictions are all correct. The dogs were identified, and the monkey is marked as “not dog”.