Implementing ResNet with Base Line Accuracy

 Implementing ResNet with Base Line Accuracy  

ResNet Base Line Accuracies 

 

Model 

Size (MB) 

Top-1 Accuracy 

Top-5 Accuracy 

Parameters 

Depth 

Time (ms) per inference step (CPU) 

Time (ms) per inference step (GPU) 

98 

0.749 

0.921 

25,636,712 

- 

58.20 

4.55 

171 

0.764 

0.928 

44,707,176 

- 

89.59 

5.19 

 

Results Summary & Comparison (Reasons and the Implementations described below) 

Model 

Size (MB) 

Base Line Top-1 Accuracy 

Actual Base Line Top 1 Accuracy 

98 

74.9 % 

68.084 % 

171 

76.4 % 

69.976 % 

 

ResNet 50 Validation Test Results 

Data Set: ImageNet Validation data set (50,000 images)  

Validation Accuracy (Top1) = 68.084 % with caffe input preprocessing 

 

ResNet 101 Validation Test Results 

Data Set: ImageNet Validation data set (50,000 images) 

Validation Accuracy (Top1) = 69.976 % with caffe input preprocessing 

 

Base Line Setup Details 

 

  1. Load the images in the format of RGB channel ordering (size = 224, 224, 3) 
  2. Convert images in to an array  
  3. Expand the image dimension by one  
  4. Preprocess Input (on tf, torch and caffe modes) 

 
Mode is one of "caffe", "tf" or "torch". Defaults to "caffe". 

 

  • caffe: will convert the images from RGB to BGR, then will zero-center each color channel with respect to the ImageNet dataset, without scaling. 

  • tf: will scale pixels between -1 and 1, sample-wise. 

  • torch: will scale pixels between 0 and 1 and then will normalize each channel with respect to the ImageNet dataset. 


     5.Call predict  

 

Tested ResNet101 on all 3 input preprocessing modes 

  1. caffe = 71.5% (Top1 Accuracy) with 1000 validation images 
  2. tf = 0.3% (Top1 Accuracy) with 1000 validation images 
  3. torch = 0.89% (Top1 Accuracy) with 1000 validation images 

Out of all three modes, caffe mode has the highest accuracy 

 

ResNet Baseline Validation Script TensorFlow 1.15 

Install TensorFlow 1.15 

  1. Install python 3.6 
  2. Create a new PyCharm project 
  3. Select python 3.6 interpreter 
  4. Create VENV 
  5. Pip install tensorflow==1.15 

Python 3.6 

Tensorflow 1.15 

Requirements file link

https://github.com/SaralaSewwandi/ResNet-BaseLine-Validation/blob/main/Tensoflow%201.15%20Libray%20Requirements/requirements.txt

 

 

Error with resnet decode fix in tensorflow 1.15 

resolved AttributeError: 'str' object has no attribute 'decode' 

pip install 'h5py==2.10.0' --force-reinstall 

 

Final TensorFlow Script is written in order to eb compatible with both the TensorFlow versions 2 and 1.5 

 

ResNet Baseline Validation Script TensorFlow 

python 3.9  

tensorflow 2.7 


 

Tasks Performed 

  1. Implemented the script for TensorFlow 2 & Tensorflow 1.15 
  2. Tested for all the preprocessing modes for the base line accuracy (TF, TORCH and CAFFE) 
  3. Image size is fine = 224,224,3 
  4. Channel ordering and conversion to RGB to BGR confirmed 
  5. Input Preprocessing Done According to the API 
  6. Inference Validation Script debugged  
  7. Tested for all the details mentioned in the Keras site to reproduce the baseline accuruacy 
  8. Only thing left to check is whether we are evaluating based on the exact validation data set that they were providing the accuracy on. 
  9. We have used the 2012 ImageNet Validation dataset 
  10. However, between 2012, 2014 & 2017 there will be changes in labels (which were corrected over time) 
  11. So ResNet101 and ResNet50 is to be tested on 2014 ImageNet Validation dataset  


 

ImageNet Class IDs with Labels 

Official Link (here first line has the value background just to avoid the index 0, and assign the indexes from 1 – 1000 for the imagenet class ids) 

 

 

Other References 

 


Final Python Scripts

ResNet Validation Script is developed to support both the TensorFlow 2 and Tensorflow1.15 versions

https://github.com/SaralaSewwandi/ResNet-BaseLine-Validation
 

 

 

 

 

 

 

 

Comments

Popular posts from this blog

How to build CppRestSDK using Vcpkg in Visual Studio 2019 (X64 windows & X86 windows)

How to Call Webservice through C++ Dynamic Link Library (DLL) in Visual Studio 2019 Using C++ Rest SDK