<jupyter_start><jupyter_text>**Mask R-CNN instance segmentation with custom dataset in Google Colab**Jupyter notebook providing steps to train a **Mask R-CNN** model with custom dataset. Requirements are only dataset images and annotations file which you can get it from [here](https://github.com/rakehsaleem/Crack-Detection-TF-1.x.x/releases/tag/v1.0)**Colab Runtime type: Python3, GPU enabled.** **Making Dataset**I generated dataset annotations with [VGG Image Annotator](https://www.robots.ox.ac.uk/~vgg/software/via/).Notebook train a model for one class object detection. It is possible to slightly modify notebook to train model for multiple classes.Before running notebook, we need to create dataset:1. Collect various pictures of objects to detect2. Create annotation files in VGG3. Create image.zip file having structure defined below4. Upload the zip file in your Google DriveZip file structure:```images.zip|- "train" directory  |- jpg image files of training data  |- "via_region_data.json" annotations file of training data|- "val" directory  |- jpg image files of validation data  |- "via_region_data.json" annotations file of validation data```Check my image.zip file as dataset example.  Install required packages<jupyter_code>%cd

!git clone --quiet https://github.com/rakehsaleem/Crack-Detection-TF-1.x.x.git
%cd ~/Crack-Detection-TF-1.x.x

!pip uninstall -y tensorflow
!pip install tensorflow==1.14.0
!pip install keras==2.2.4
import tensorflow as tf
print(tf.__version__)
!pip install -q PyDrive
!pip install -r requirements.txt
!python setup.py install<jupyter_output>/root/Crack-Detection-TF-1.x.x
Found existing installation: tensorflow 2.6.0
Uninstalling tensorflow-2.6.0:
  Successfully uninstalled tensorflow-2.6.0
Collecting tensorflow==1.14.0
  Downloading tensorflow-1.14.0-cp37-cp37m-manylinux1_x86_64.whl (109.3 MB)
[K     |████████████████████████████████| 109.3 MB 46 kB/s 
[?25hRequirement already satisfied: absl-py>=0.7.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow==1.14.0) (0.12.0)
Requirement already satisfied: astor>=0.6.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow==1.14.0) (0.8.1)
Requirement already satisfied: gast>=0.2.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow==1.14.0) (0.4.0)
Requirement already satisfied: wrapt>=1.11.1 in /usr/local/lib/python3.7/dist-packages (from tensorflow==1.14.0) (1.12.1)
Requirement already satisfied: grpcio>=1.8.6 in /usr/local/lib/python3.7/dist-packages (from tensorflow==1.14.0) (1.39.0)
Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/pyt[...]<jupyter_text>**Dataset Preparation and set up locations**<jupyter_code>%cd ~/Crack-Detection-TF-1.x.x
fileId = '12bCRgVoRaegFY7xQ2h6qmFrMKz8AtLZt'

import os
from zipfile import ZipFile
from shutil import copy
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

os.makedirs('dataset')
os.chdir('dataset')

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

fileName = fileId + '.zip'
downloaded = drive.CreateFile({'id': fileId})
downloaded.GetContentFile(fileName)
ds = ZipFile(fileName)
ds.extractall()
os.remove(fileName)
print('Extracted zip file ' + fileName)
%cd ~/Crack-Detection-TF-1.x.x

!cp ~/Crack-Detection-TF-1.x.x/crack/crack.py ./crack.py

!sed -i -- 's/epochs=30/epochs=5/g' crack.py<jupyter_output>/root/Crack-Detection-TF-1.x.x<jupyter_text>Training StartsIf for some reason you get error related to keras, locate the file with error and go to file line to modify these two lines:```original_keras_version = f.attrs['keras_version'].decode('utf8')original_backend = f.attrs['backend'].decode('utf8')tooriginal_keras_version = f.attrs['keras_version']original_backend = f.attrs['backend']```<jupyter_code>%cd ~/Crack-Detection-TF-1.x.x

!python crack.py train --dataset=dataset/Dataset3 --weights=coco<jupyter_output>/root/Crack-Detection-TF-1.x.x
Using TensorFlow backend.
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/fram[...]
{'fraction_non_alphanumeric': 0.1399004975124378, 'fraction_numerical': 0.037014925373134326, 'mean_word_length': 5.106925880923451, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '36003', 'license': 'MIT', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1745, 'n_words': 451, 'path': 'Mask_R_CNN_colab.ipynb', 'repo_name': 'rakehsaleem/Custom_Mask_RCNN', 'size': '5025'}