<jupyter_start><jupyter_text>Faster R CNN Implementation using Tensorflow**Dataset** : [OpenImagesDataset](https://opensource.google/projects/open-images-dataset)**Framework** : Tensorflow<jupyter_code>%rm -r "/content/faster-r-cnn-tf"<jupyter_output>rm: cannot remove '/content/faster-r-cnn-tf': No such file or directory<jupyter_text>Git CloneCloning the git repository to our running direcotory<jupyter_code>!git clone https://github.com/pishangujeniya/faster-r-cnn-tf.git<jupyter_output>Cloning into 'faster-r-cnn-tf'...
remote: Enumerating objects: 27, done.[K
remote: Counting objects: 100% (27/27), done.[K
remote: Compressing objects: 100% (23/23), done.[K
remote: Total 27 (delta 1), reused 24 (delta 1), pack-reused 0[K
Unpacking objects: 100% (27/27), done.<jupyter_text>Need to install the required libraries(Or simply install `!pip install wget` because only that library is not existing in Google Colab, other all are already available in Google Colab<jupyter_code>!pip install -r /content/faster-r-cnn-tf/requirements.txt<jupyter_output>Requirement already satisfied: Keras>=2.4.3 in /usr/local/lib/python3.7/dist-packages (from -r /content/faster-r-cnn-tf/requirements.txt (line 1)) (2.4.3)
Requirement already satisfied: tensorflow>=2.4.1 in /usr/local/lib/python3.7/dist-packages (from -r /content/faster-r-cnn-tf/requirements.txt (line 2)) (2.5.0)
Requirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.7/dist-packages (from -r /content/faster-r-cnn-tf/requirements.txt (line 3)) (1.19.5)
Collecting opencv-python>=4.5.1.48
[?25l  Downloading https://files.pythonhosted.org/packages/72/b3/3878691fec6babd78bbf4c71c720e1831cbb6ada61679613fe2fae080568/opencv_python-4.5.2.54-cp37-cp37m-manylinux2014_x86_64.whl (51.0MB)
[K     |████████████████████████████████| 51.0MB 57kB/s 
[?25hCollecting scikit-learn>=0.24.1
[?25l  Downloading https://files.pythonhosted.org/packages/a8/eb/a48f25c967526b66d5f1fa7a984594f0bf0a5afafa94a8c4dbc317744620/scikit_learn-0.24.2-cp37-cp37m-manylinux2010_x86_64.whl (22.3MB)
[K     |█[...]<jupyter_text>Using VGG16 Pre-Trained WeightsDownload the pre-trained VGG16 Weights so that we can have our model pre-trained to basic features of the images.<jupyter_code>!wget "https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5" -O "/content/faster-r-cnn-tf/OpenImagesDataset/vgg16_weights_tf_dim_ordering_tf_kernels.h5"<jupyter_output>--2021-06-19 15:48:06--  https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5
Resolving github.com (github.com)... 192.168.127.12
Connecting to github.com (github.com)|192.168.127.12|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/64878964/b0afbae8-5983-11e6-90f4-e3db656bd548?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210619%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210619T154806Z&X-Amz-Expires=300&X-Amz-Signature=47c80aa178a21252c27b0a4a891b899ed650a165526af577d40125f3d63895eb&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=64878964&response-content-disposition=attachment%3B%20filename%3Dvgg16_weights_tf_dim_ordering_tf_kernels.h5&response-content-type=application%2Foctet-stream [following]
--2021-06-19 15:48:06--  https://github-releases.githubusercontent.com/64878964/b0afbae8-5983-11e6-90f4-e3db656bd548?X-Amz-[...]<jupyter_text>Adding our working directory to the Jupyter Notebook Path, so that python files from that directory can be used.> You can explore and see the codes of python files from file browser of Google Colab inside the `/content/faster-r-cnn-tf` directory.<jupyter_code>import os
import sys
MAIN_DIR_PATH = os.path.abspath("/content/faster-r-cnn-tf")
sys.path.append(MAIN_DIR_PATH)<jupyter_output><empty_output><jupyter_text>TrainingRunning the main function which will start training the model.> For more information check the code of `main.py` file.<jupyter_code>from main import Main
main_var = Main(MAIN_DIR_PATH=MAIN_DIR_PATH)

main_var.main(resume_weights_model_name=None,download_open_images_dataset=True, generate_subset=True)

# Resuming Training from pre-trained model
# main_var.main(resume_weights_model_name="model_frcnn.vgg_0150.hdf5", download_open_images_dataset=False, generate_subset=False)<jupyter_output>Downloading of BBOX csv file starting...
Downloading of BBOX csv file completed
Downloading of Image Details csv file starting...
Downloading of Image Details csv file completed
Downloading of Class Labels csv file starting...
Downloading of Class Labels csv file completed
Downloading images for training is starting...
Downloading images for testing is starting...
Generating annotation for training is starting...
Generating annotation for testing is starting...
Parsing annotation files
Parsing annotation files
Training images per class:
{'Apple': 565, 'Grape': 556, 'Potato': 274, 'bg': 0}
Num classes (including bg) = 4
Config has been written to /content/faster-r-cnn-tf/OpenImagesDataset/config.pickle, and can be loaded when testing to ensure correct results
Num train samples (images) 406
Num val samples 406
loading weights from /content/faster-r-cnn-tf/OpenImagesDataset/vgg16_weights_tf_dim_ordering_tf_kernels.h5<jupyter_text>TestingRunning the test function with our custom images loaded into some directory, and our model will embed the labelled bounding box and store them into output directory.<jupyter_code># Testing the model...
main_var.test(
        trained_model_path=os.path.join(MAIN_DIR_PATH,"OpenImagesDataset","models","model_frcnn.vgg_0218.hdf5"),
        config_path=os.path.join(MAIN_DIR_PATH,"OpenImagesDataset","config.pickle"),
        input_images_dir_path=os.path.join(MAIN_DIR_PATH,"OpenImagesDataset","images","test"),
        output_dir_path=os.path.join(MAIN_DIR_PATH,"OpenImagesDataset","images","output"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12075597926074594, 'fraction_numerical': 0.07593243017226961, 'mean_word_length': 6.248484848484848, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 31, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '361986', 'license': 'MIT', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2120, 'n_words': 420, 'path': 'faster_r_cnn_tf.ipynb', 'repo_name': 'pishangujeniya/Faster-R-CNN-tf', 'size': '5975'}