This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import glob | |
import matplotlib | |
import matplotlib.pyplot as plt | |
import io | |
import scipy.misc | |
import numpy as np | |
from six import BytesIO | |
from PIL import Image, ImageDraw, ImageFont |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#run conversion script to save the retrained model: | |
#Saved model will be in saved_model.pb file: | |
import re | |
import numpy as np | |
output_directory = '/content/fine_tuned_model' | |
#place the model weights you would like to export here | |
last_model_path = '/content/training/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!python /content/models/research/object_detection/model_main_tf2.py \ | |
--pipeline_config_path={pipeline_file} \ | |
--model_dir={model_dir} \ | |
--alsologtostderr \ | |
--num_train_steps={num_steps} \ | |
--sample_1_of_n_eval_examples=1 \ | |
--num_eval_steps={num_eval_steps} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Download pretrained weights | |
%mkdir /content/deploy/ | |
%cd /content/deploy/ | |
import tarfile | |
download_tar = 'http://download.tensorflow.org/models/object_detection/tf2/20200711/' + pretrained_checkpoint | |
!wget {download_tar} | |
tar = tarfile.open(pretrained_checkpoint) | |
tar.extractall() | |
tar.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#You can change chosen model to deploy different models available in the TF2 object detection zoo | |
MODELS_CONFIG = { | |
'ssd_mobilenet_v2_320x320_coco17': { | |
'model_name': 'ssd_mobilenet_v2_320x320_coco17_tpu-8', | |
'base_pipeline_file': 'ssd_mobilenet_v2_320x320_coco17_tpu-8.config', | |
'pretrained_checkpoint': 'ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz', | |
'batch_size': 16 | |
} | |
} | |
chosen_model = 'ssd_mobilenet_v2_320x320_coco17' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Downloading data Training set made by Roboflow | |
%cd /content | |
#Download Training set from git by cloning rep: | |
import os | |
import pathlib | |
# Clone the training set repository if it doesn't already exist | |
if "RetrainModelExample" in pathlib.Path.cwd().parts: | |
while "RetrainModelExample" in pathlib.Path.cwd().parts: | |
os.chdir('..') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib | |
import matplotlib.pyplot as plt | |
import os | |
import random | |
import io | |
import imageio | |
import glob | |
import scipy.misc | |
import numpy as np |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install the Object Detection API | |
%%bash | |
cd /content/models/research/ | |
protoc object_detection/protos/*.proto --python_out=. | |
cp object_detection/packages/tf2/setup.py . | |
python -m pip install . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pathlib | |
# Clone the tensorflow models repository if it doesn't already exist | |
if "models" in pathlib.Path.cwd().parts: | |
while "models" in pathlib.Path.cwd().parts: | |
os.chdir('..') | |
elif not pathlib.Path('models').exists(): | |
!git clone --depth 1 https://github.com/tensorflow/models |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder