123 KiB
Training YOLOv3 object detection on a custom dataset
💡 Recommendation: Open this blog post to continue.
Overview
This notebook walks through how to train a YOLOv3 object detection model on your own dataset using Roboflow and Colab.
In this specific example, we'll training an object detection model to recognize chess pieces in images. To adapt this example to your own dataset, you only need to change one line of code in this notebook.
Our Data
Our dataset of 289 chess images (and 2894 annotations!) is hosted publicly on Roboflow here.
Our Model
We'll be training a YOLOv3 (You Only Look Once) model. This specific model is a one-shot learner, meaning each image only passes through the network once to make a prediction, which allows the architecture to be very performant, viewing up to 60 frames per second in predicting against video feeds.
The GitHub repo containing the majority of the code we'll use is available here.
Training
Google Colab provides free GPU resources. Click "Runtime" → "Change runtime type" → Hardware Accelerator dropdown to "GPU."
Colab does have memory limitations, and notebooks must be open in your browser to run. Sessions automatically clear themselves after 24 hours.
Inference
We'll leverage the python_video.py
script to produce predictions. Arguments are specified below.
It's recommended that you expand the left-hand panel to view this notebook's Table of contents, Code Snippets, and Files.
Then, click "Files." You'll see files appear here as we work through the notebook.
About
Roboflow makes managing, preprocessing, augmenting, and versioning datasets for computer vision seamless.
Developers reduce 50% of their boilerplate code when using Roboflow's workflow, save training time, and increase model reproducibility.
Setup our environment
First, we'll install the version of Keras our YOLOv3 implementation calls for and verify it installs corrects.
# Get our kernel running
print("Hello, Roboflow")
Hello, Roboflow
# Our YOLOv3 implementation calls for this Keras version
!pip install keras==2.2.4
Collecting keras==2.2.4 [?25l Downloading https://files.pythonhosted.org/packages/5e/10/aa32dad071ce52b5502266b5c659451cfd6ffcbf14e6c8c4f16c0ff5aaab/Keras-2.2.4-py2.py3-none-any.whl (312kB) [K |█ | 10kB 22.0MB/s eta 0:00:01 [K |██ | 20kB 27.1MB/s eta 0:00:01 [K |███▏ | 30kB 30.9MB/s eta 0:00:01 [K |████▏ | 40kB 31.0MB/s eta 0:00:01 [K |█████▎ | 51kB 18.5MB/s eta 0:00:01 [K |██████▎ | 61kB 17.0MB/s eta 0:00:01 [K |███████▍ | 71kB 16.1MB/s eta 0:00:01 [K |████████▍ | 81kB 17.6MB/s eta 0:00:01 [K |█████████▍ | 92kB 15.1MB/s eta 0:00:01 [K |██████████▌ | 102kB 15.5MB/s eta 0:00:01 [K |███████████▌ | 112kB 15.5MB/s eta 0:00:01 [K |████████████▋ | 122kB 15.5MB/s eta 0:00:01 [K |█████████████▋ | 133kB 15.5MB/s eta 0:00:01 [K |██████████████▊ | 143kB 15.5MB/s eta 0:00:01 [K |███████████████▊ | 153kB 15.5MB/s eta 0:00:01 [K |████████████████▊ | 163kB 15.5MB/s eta 0:00:01 [K |█████████████████▉ | 174kB 15.5MB/s eta 0:00:01 [K |██████████████████▉ | 184kB 15.5MB/s eta 0:00:01 [K |████████████████████ | 194kB 15.5MB/s eta 0:00:01 [K |█████████████████████ | 204kB 15.5MB/s eta 0:00:01 [K |██████████████████████ | 215kB 15.5MB/s eta 0:00:01 [K |███████████████████████ | 225kB 15.5MB/s eta 0:00:01 [K |████████████████████████▏ | 235kB 15.5MB/s eta 0:00:01 [K |█████████████████████████▏ | 245kB 15.5MB/s eta 0:00:01 [K |██████████████████████████▏ | 256kB 15.5MB/s eta 0:00:01 [K |███████████████████████████▎ | 266kB 15.5MB/s eta 0:00:01 [K |████████████████████████████▎ | 276kB 15.5MB/s eta 0:00:01 [K |█████████████████████████████▍ | 286kB 15.5MB/s eta 0:00:01 [K |██████████████████████████████▍ | 296kB 15.5MB/s eta 0:00:01 [K |███████████████████████████████▌| 307kB 15.5MB/s eta 0:00:01 [K |████████████████████████████████| 317kB 15.5MB/s [?25hRequirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from keras==2.2.4) (3.13) Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.6/dist-packages (from keras==2.2.4) (1.12.0) Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (from keras==2.2.4) (2.10.0) Requirement already satisfied: keras-applications>=1.0.6 in /usr/local/lib/python3.6/dist-packages (from keras==2.2.4) (1.0.8) Requirement already satisfied: scipy>=0.14 in /usr/local/lib/python3.6/dist-packages (from keras==2.2.4) (1.4.1) Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.6/dist-packages (from keras==2.2.4) (1.18.2) Requirement already satisfied: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.6/dist-packages (from keras==2.2.4) (1.1.0) Installing collected packages: keras Found existing installation: Keras 2.3.1 Uninstalling Keras-2.3.1: Successfully uninstalled Keras-2.3.1 Successfully installed keras-2.2.4
# use TF 1.x
%tensorflow_version 1.x
TensorFlow 1.x selected.
# Verify our version is correct
!python -c 'import keras; print(keras.__version__)'
Using TensorFlow backend. 2.2.4
# Next, we'll grab all the code from our repository of interest
!git clone https://github.com/roboflow-ai/keras-yolo3.git
Cloning into 'keras-yolo3'...
remote: Enumerating objects: 165, done.[K
Receiving objects: 100% (165/165), 156.01 KiB | 300.00 KiB/s, done.
remote: Total 165 (delta 0), reused 0 (delta 0), pack-reused 165
Resolving deltas: 100% (79/79), done.
# here's what we cloned (also, see "Files" in the left-hand Colab pane)
%ls
[0m[01;34mkeras-yolo3[0m/ [01;34msample_data[0m/
# change directory to the repo we cloned
%cd keras-yolo3/
/content/keras-yolo3
# show the contents of our repo
%ls
coco_annotation.py kmeans.py train_bottleneck.py yolo.py convert.py LICENSE train.py yolov3.cfg darknet53.cfg [0m[01;34mmodel_data[0m/ voc_annotation.py yolov3-tiny.cfg [01;34mfont[0m/ README.md [01;34myolo3[0m/ yolo_video.py
Get our training data from Roboflow
Next, we need to add our data from Roboflow into our environment.
Our dataset, with annotations, is here.
Here's how to bring those images from Roboflow to Colab:
- Visit this link.
- Click the "416x416auto-orient" under Downloads.
- On the dataset detail page, select "Download" in the upper right-hand corner.
- If you are not signed in, you will be prompted to create a free account (sign in with GitHub or email), and redirected to the dataset page to Download.
- On the download popup, select the YOLOv3 Keras option and the "Show download
code
". - Copy the code snippet Roboflow generates for you, and paste it in the next cell.
This is the download menu you want (from step 5):
The top code snippet is the one you want to copy (from step 6) and paste in the next notebook cell:
This cell below is only one you need to change to have YOLOv3 train on your own Roboflow dataset.
# Paste Roboflow code from snippet here from above to here! eg !curl -L https://app.roboflow.ai/ds/eOSXbt7KWu?key=YOURKEY | jar -x
!curl -L https://app.roboflow.ai/ds/REPLACE-THIS-LINk > roboflow.zip; unzip roboflow.zip; rm roboflow.zip
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 27 100 27 0 0 59 0 --:--:-- --:--:-- --:--:-- 59 Archive: roboflow.zip End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of roboflow.zip or roboflow.zip.zip, and cannot find roboflow.zip.ZIP, period.
%ls
coco_annotation.py kmeans.py train_bottleneck.py yolo.py convert.py LICENSE train.py yolov3.cfg darknet53.cfg [0m[01;34mmodel_data[0m/ voc_annotation.py yolov3-tiny.cfg [01;34mfont[0m/ README.md [01;34myolo3[0m/ yolo_video.py
# change directory into our export folder from Roboflow
%cd train
[Errno 2] No such file or directory: 'train' /content/keras-yolo3
# show what came with the Roboflow export
%ls
coco_annotation.py kmeans.py train_bottleneck.py yolo.py convert.py LICENSE train.py yolov3.cfg darknet53.cfg [0m[01;34mmodel_data[0m/ voc_annotation.py yolov3-tiny.cfg [01;34mfont[0m/ README.md [01;34myolo3[0m/ yolo_video.py
# move everything from the Roboflow export to the root of our keras-yolo3 folder
%mv * ../
# change directory back to our
%cd ..
/content
# show that all our images, _annotations.txt, and _classes.txt made it to our root directory
%ls
coco_annotation.py kmeans.py train_bottleneck.py yolov3.cfg convert.py LICENSE train.py yolov3-tiny.cfg darknet53.cfg [0m[01;34mmodel_data[0m/ voc_annotation.py yolo_video.py [01;34mfont[0m/ README.md [01;34myolo3[0m/ [01;34mkeras-yolo3[0m/ [01;34msample_data[0m/ yolo.py
Set up and train our model
Next, we'll download pre-trained weighs weights from DarkNet, set up our YOLOv3 architecture with those pre-trained weights, and initiate training.
# download our DarkNet weights
!wget https://pjreddie.com/media/files/yolov3.weights
--2020-04-17 20:07:32-- https://pjreddie.com/media/files/yolov3.weights Resolving pjreddie.com (pjreddie.com)... 128.208.4.108 Connecting to pjreddie.com (pjreddie.com)|128.208.4.108|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 248007048 (237M) [application/octet-stream] Saving to: ‘yolov3.weights’ yolov3.weights 100%[===================>] 236.52M 254KB/s in 12m 13s 2020-04-17 20:19:47 (330 KB/s) - ‘yolov3.weights’ saved [248007048/248007048]
# call a Python script to set up our architecture with downloaded pre-trained weights
!python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5
Using TensorFlow backend. Loading weights. Weights Header: 0 2 0 [32013312] Parsing Darknet config. Creating Keras model. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead. Parsing section net_0 Parsing section convolutional_0 conv2d bn leaky (3, 3, 3, 32) WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:174: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:181: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:186: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead. 2020-04-17 20:19:52.070888: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX512F 2020-04-17 20:19:52.147911: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2000120000 Hz 2020-04-17 20:19:52.148388: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x19b8a00 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2020-04-17 20:19:52.148429: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 2020-04-17 20:19:52.153494: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1 2020-04-17 20:19:52.378955: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-04-17 20:19:52.379755: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x19b8bc0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices: 2020-04-17 20:19:52.379790: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Tesla T4, Compute Capability 7.5 2020-04-17 20:19:52.381224: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-04-17 20:19:52.381958: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: name: Tesla T4 major: 7 minor: 5 memoryClockRate(GHz): 1.59 pciBusID: 0000:00:04.0 2020-04-17 20:19:52.382253: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1 2020-04-17 20:19:52.383893: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10 2020-04-17 20:19:52.385764: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10 2020-04-17 20:19:52.386109: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10 2020-04-17 20:19:52.387660: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10 2020-04-17 20:19:52.412685: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10 2020-04-17 20:19:52.415845: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7 2020-04-17 20:19:52.415946: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-04-17 20:19:52.416522: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-04-17 20:19:52.417026: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0 2020-04-17 20:19:52.422944: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1 2020-04-17 20:19:52.424063: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix: 2020-04-17 20:19:52.424093: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186] 0 2020-04-17 20:19:52.424104: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0: N 2020-04-17 20:19:52.426496: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-04-17 20:19:52.427106: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-04-17 20:19:52.427711: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0. 2020-04-17 20:19:52.427755: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14221 MB memory) -> physical GPU (device: 0, name: Tesla T4, pci bus id: 0000:00:04.0, compute capability: 7.5) WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:190: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:199: The name tf.is_variable_initialized is deprecated. Please use tf.compat.v1.is_variable_initialized instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:206: The name tf.variables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1834: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:133: The name tf.placeholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead. Parsing section convolutional_1 conv2d bn leaky (3, 3, 32, 64) Parsing section convolutional_2 conv2d bn leaky (1, 1, 64, 32) Parsing section convolutional_3 conv2d bn leaky (3, 3, 32, 64) Parsing section shortcut_0 Parsing section convolutional_4 conv2d bn leaky (3, 3, 64, 128) Parsing section convolutional_5 conv2d bn leaky (1, 1, 128, 64) Parsing section convolutional_6 conv2d bn leaky (3, 3, 64, 128) Parsing section shortcut_1 Parsing section convolutional_7 conv2d bn leaky (1, 1, 128, 64) Parsing section convolutional_8 conv2d bn leaky (3, 3, 64, 128) Parsing section shortcut_2 Parsing section convolutional_9 conv2d bn leaky (3, 3, 128, 256) Parsing section convolutional_10 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_11 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_3 Parsing section convolutional_12 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_13 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_4 Parsing section convolutional_14 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_15 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_5 Parsing section convolutional_16 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_17 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_6 Parsing section convolutional_18 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_19 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_7 Parsing section convolutional_20 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_21 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_8 Parsing section convolutional_22 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_23 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_9 Parsing section convolutional_24 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_25 conv2d bn leaky (3, 3, 128, 256) Parsing section shortcut_10 Parsing section convolutional_26 conv2d bn leaky (3, 3, 256, 512) Parsing section convolutional_27 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_28 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_11 Parsing section convolutional_29 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_30 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_12 Parsing section convolutional_31 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_32 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_13 Parsing section convolutional_33 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_34 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_14 Parsing section convolutional_35 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_36 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_15 Parsing section convolutional_37 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_38 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_16 Parsing section convolutional_39 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_40 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_17 Parsing section convolutional_41 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_42 conv2d bn leaky (3, 3, 256, 512) Parsing section shortcut_18 Parsing section convolutional_43 conv2d bn leaky (3, 3, 512, 1024) Parsing section convolutional_44 conv2d bn leaky (1, 1, 1024, 512) Parsing section convolutional_45 conv2d bn leaky (3, 3, 512, 1024) Parsing section shortcut_19 Parsing section convolutional_46 conv2d bn leaky (1, 1, 1024, 512) Parsing section convolutional_47 conv2d bn leaky (3, 3, 512, 1024) Parsing section shortcut_20 Parsing section convolutional_48 conv2d bn leaky (1, 1, 1024, 512) Parsing section convolutional_49 conv2d bn leaky (3, 3, 512, 1024) Parsing section shortcut_21 Parsing section convolutional_50 conv2d bn leaky (1, 1, 1024, 512) Parsing section convolutional_51 conv2d bn leaky (3, 3, 512, 1024) Parsing section shortcut_22 Parsing section convolutional_52 conv2d bn leaky (1, 1, 1024, 512) Parsing section convolutional_53 conv2d bn leaky (3, 3, 512, 1024) Parsing section convolutional_54 conv2d bn leaky (1, 1, 1024, 512) Parsing section convolutional_55 conv2d bn leaky (3, 3, 512, 1024) Parsing section convolutional_56 conv2d bn leaky (1, 1, 1024, 512) Parsing section convolutional_57 conv2d bn leaky (3, 3, 512, 1024) Parsing section convolutional_58 conv2d linear (1, 1, 1024, 255) Parsing section yolo_0 Parsing section route_0 Parsing section convolutional_59 conv2d bn leaky (1, 1, 512, 256) Parsing section upsample_0 WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:2018: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead. Parsing section route_1 Concatenating route layers: [<tf.Tensor 'up_sampling2d_1/ResizeNearestNeighbor:0' shape=(?, ?, ?, 256) dtype=float32>, <tf.Tensor 'add_19/add:0' shape=(?, ?, ?, 512) dtype=float32>] Parsing section convolutional_60 conv2d bn leaky (1, 1, 768, 256) Parsing section convolutional_61 conv2d bn leaky (3, 3, 256, 512) Parsing section convolutional_62 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_63 conv2d bn leaky (3, 3, 256, 512) Parsing section convolutional_64 conv2d bn leaky (1, 1, 512, 256) Parsing section convolutional_65 conv2d bn leaky (3, 3, 256, 512) Parsing section convolutional_66 conv2d linear (1, 1, 512, 255) Parsing section yolo_1 Parsing section route_2 Parsing section convolutional_67 conv2d bn leaky (1, 1, 256, 128) Parsing section upsample_1 Parsing section route_3 Concatenating route layers: [<tf.Tensor 'up_sampling2d_2/ResizeNearestNeighbor:0' shape=(?, ?, ?, 128) dtype=float32>, <tf.Tensor 'add_11/add:0' shape=(?, ?, ?, 256) dtype=float32>] Parsing section convolutional_68 conv2d bn leaky (1, 1, 384, 128) Parsing section convolutional_69 conv2d bn leaky (3, 3, 128, 256) Parsing section convolutional_70 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_71 conv2d bn leaky (3, 3, 128, 256) Parsing section convolutional_72 conv2d bn leaky (1, 1, 256, 128) Parsing section convolutional_73 conv2d bn leaky (3, 3, 128, 256) Parsing section convolutional_74 conv2d linear (1, 1, 256, 255) Parsing section yolo_2 __________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ================================================================================================== input_1 (InputLayer) (None, None, None, 3 0 __________________________________________________________________________________________________ conv2d_1 (Conv2D) (None, None, None, 3 864 input_1[0][0] __________________________________________________________________________________________________ batch_normalization_1 (BatchNor (None, None, None, 3 128 conv2d_1[0][0] __________________________________________________________________________________________________ leaky_re_lu_1 (LeakyReLU) (None, None, None, 3 0 batch_normalization_1[0][0] __________________________________________________________________________________________________ zero_padding2d_1 (ZeroPadding2D (None, None, None, 3 0 leaky_re_lu_1[0][0] __________________________________________________________________________________________________ conv2d_2 (Conv2D) (None, None, None, 6 18432 zero_padding2d_1[0][0] __________________________________________________________________________________________________ batch_normalization_2 (BatchNor (None, None, None, 6 256 conv2d_2[0][0] __________________________________________________________________________________________________ leaky_re_lu_2 (LeakyReLU) (None, None, None, 6 0 batch_normalization_2[0][0] __________________________________________________________________________________________________ conv2d_3 (Conv2D) (None, None, None, 3 2048 leaky_re_lu_2[0][0] __________________________________________________________________________________________________ batch_normalization_3 (BatchNor (None, None, None, 3 128 conv2d_3[0][0] __________________________________________________________________________________________________ leaky_re_lu_3 (LeakyReLU) (None, None, None, 3 0 batch_normalization_3[0][0] __________________________________________________________________________________________________ conv2d_4 (Conv2D) (None, None, None, 6 18432 leaky_re_lu_3[0][0] __________________________________________________________________________________________________ batch_normalization_4 (BatchNor (None, None, None, 6 256 conv2d_4[0][0] __________________________________________________________________________________________________ leaky_re_lu_4 (LeakyReLU) (None, None, None, 6 0 batch_normalization_4[0][0] __________________________________________________________________________________________________ add_1 (Add) (None, None, None, 6 0 leaky_re_lu_2[0][0] leaky_re_lu_4[0][0] __________________________________________________________________________________________________ zero_padding2d_2 (ZeroPadding2D (None, None, None, 6 0 add_1[0][0] __________________________________________________________________________________________________ conv2d_5 (Conv2D) (None, None, None, 1 73728 zero_padding2d_2[0][0] __________________________________________________________________________________________________ batch_normalization_5 (BatchNor (None, None, None, 1 512 conv2d_5[0][0] __________________________________________________________________________________________________ leaky_re_lu_5 (LeakyReLU) (None, None, None, 1 0 batch_normalization_5[0][0] __________________________________________________________________________________________________ conv2d_6 (Conv2D) (None, None, None, 6 8192 leaky_re_lu_5[0][0] __________________________________________________________________________________________________ batch_normalization_6 (BatchNor (None, None, None, 6 256 conv2d_6[0][0] __________________________________________________________________________________________________ leaky_re_lu_6 (LeakyReLU) (None, None, None, 6 0 batch_normalization_6[0][0] __________________________________________________________________________________________________ conv2d_7 (Conv2D) (None, None, None, 1 73728 leaky_re_lu_6[0][0] __________________________________________________________________________________________________ batch_normalization_7 (BatchNor (None, None, None, 1 512 conv2d_7[0][0] __________________________________________________________________________________________________ leaky_re_lu_7 (LeakyReLU) (None, None, None, 1 0 batch_normalization_7[0][0] __________________________________________________________________________________________________ add_2 (Add) (None, None, None, 1 0 leaky_re_lu_5[0][0] leaky_re_lu_7[0][0] __________________________________________________________________________________________________ conv2d_8 (Conv2D) (None, None, None, 6 8192 add_2[0][0] __________________________________________________________________________________________________ batch_normalization_8 (BatchNor (None, None, None, 6 256 conv2d_8[0][0] __________________________________________________________________________________________________ leaky_re_lu_8 (LeakyReLU) (None, None, None, 6 0 batch_normalization_8[0][0] __________________________________________________________________________________________________ conv2d_9 (Conv2D) (None, None, None, 1 73728 leaky_re_lu_8[0][0] __________________________________________________________________________________________________ batch_normalization_9 (BatchNor (None, None, None, 1 512 conv2d_9[0][0] __________________________________________________________________________________________________ leaky_re_lu_9 (LeakyReLU) (None, None, None, 1 0 batch_normalization_9[0][0] __________________________________________________________________________________________________ add_3 (Add) (None, None, None, 1 0 add_2[0][0] leaky_re_lu_9[0][0] __________________________________________________________________________________________________ zero_padding2d_3 (ZeroPadding2D (None, None, None, 1 0 add_3[0][0] __________________________________________________________________________________________________ conv2d_10 (Conv2D) (None, None, None, 2 294912 zero_padding2d_3[0][0] __________________________________________________________________________________________________ batch_normalization_10 (BatchNo (None, None, None, 2 1024 conv2d_10[0][0] __________________________________________________________________________________________________ leaky_re_lu_10 (LeakyReLU) (None, None, None, 2 0 batch_normalization_10[0][0] __________________________________________________________________________________________________ conv2d_11 (Conv2D) (None, None, None, 1 32768 leaky_re_lu_10[0][0] __________________________________________________________________________________________________ batch_normalization_11 (BatchNo (None, None, None, 1 512 conv2d_11[0][0] __________________________________________________________________________________________________ leaky_re_lu_11 (LeakyReLU) (None, None, None, 1 0 batch_normalization_11[0][0] __________________________________________________________________________________________________ conv2d_12 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_11[0][0] __________________________________________________________________________________________________ batch_normalization_12 (BatchNo (None, None, None, 2 1024 conv2d_12[0][0] __________________________________________________________________________________________________ leaky_re_lu_12 (LeakyReLU) (None, None, None, 2 0 batch_normalization_12[0][0] __________________________________________________________________________________________________ add_4 (Add) (None, None, None, 2 0 leaky_re_lu_10[0][0] leaky_re_lu_12[0][0] __________________________________________________________________________________________________ conv2d_13 (Conv2D) (None, None, None, 1 32768 add_4[0][0] __________________________________________________________________________________________________ batch_normalization_13 (BatchNo (None, None, None, 1 512 conv2d_13[0][0] __________________________________________________________________________________________________ leaky_re_lu_13 (LeakyReLU) (None, None, None, 1 0 batch_normalization_13[0][0] __________________________________________________________________________________________________ conv2d_14 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_13[0][0] __________________________________________________________________________________________________ batch_normalization_14 (BatchNo (None, None, None, 2 1024 conv2d_14[0][0] __________________________________________________________________________________________________ leaky_re_lu_14 (LeakyReLU) (None, None, None, 2 0 batch_normalization_14[0][0] __________________________________________________________________________________________________ add_5 (Add) (None, None, None, 2 0 add_4[0][0] leaky_re_lu_14[0][0] __________________________________________________________________________________________________ conv2d_15 (Conv2D) (None, None, None, 1 32768 add_5[0][0] __________________________________________________________________________________________________ batch_normalization_15 (BatchNo (None, None, None, 1 512 conv2d_15[0][0] __________________________________________________________________________________________________ leaky_re_lu_15 (LeakyReLU) (None, None, None, 1 0 batch_normalization_15[0][0] __________________________________________________________________________________________________ conv2d_16 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_15[0][0] __________________________________________________________________________________________________ batch_normalization_16 (BatchNo (None, None, None, 2 1024 conv2d_16[0][0] __________________________________________________________________________________________________ leaky_re_lu_16 (LeakyReLU) (None, None, None, 2 0 batch_normalization_16[0][0] __________________________________________________________________________________________________ add_6 (Add) (None, None, None, 2 0 add_5[0][0] leaky_re_lu_16[0][0] __________________________________________________________________________________________________ conv2d_17 (Conv2D) (None, None, None, 1 32768 add_6[0][0] __________________________________________________________________________________________________ batch_normalization_17 (BatchNo (None, None, None, 1 512 conv2d_17[0][0] __________________________________________________________________________________________________ leaky_re_lu_17 (LeakyReLU) (None, None, None, 1 0 batch_normalization_17[0][0] __________________________________________________________________________________________________ conv2d_18 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_17[0][0] __________________________________________________________________________________________________ batch_normalization_18 (BatchNo (None, None, None, 2 1024 conv2d_18[0][0] __________________________________________________________________________________________________ leaky_re_lu_18 (LeakyReLU) (None, None, None, 2 0 batch_normalization_18[0][0] __________________________________________________________________________________________________ add_7 (Add) (None, None, None, 2 0 add_6[0][0] leaky_re_lu_18[0][0] __________________________________________________________________________________________________ conv2d_19 (Conv2D) (None, None, None, 1 32768 add_7[0][0] __________________________________________________________________________________________________ batch_normalization_19 (BatchNo (None, None, None, 1 512 conv2d_19[0][0] __________________________________________________________________________________________________ leaky_re_lu_19 (LeakyReLU) (None, None, None, 1 0 batch_normalization_19[0][0] __________________________________________________________________________________________________ conv2d_20 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_19[0][0] __________________________________________________________________________________________________ batch_normalization_20 (BatchNo (None, None, None, 2 1024 conv2d_20[0][0] __________________________________________________________________________________________________ leaky_re_lu_20 (LeakyReLU) (None, None, None, 2 0 batch_normalization_20[0][0] __________________________________________________________________________________________________ add_8 (Add) (None, None, None, 2 0 add_7[0][0] leaky_re_lu_20[0][0] __________________________________________________________________________________________________ conv2d_21 (Conv2D) (None, None, None, 1 32768 add_8[0][0] __________________________________________________________________________________________________ batch_normalization_21 (BatchNo (None, None, None, 1 512 conv2d_21[0][0] __________________________________________________________________________________________________ leaky_re_lu_21 (LeakyReLU) (None, None, None, 1 0 batch_normalization_21[0][0] __________________________________________________________________________________________________ conv2d_22 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_21[0][0] __________________________________________________________________________________________________ batch_normalization_22 (BatchNo (None, None, None, 2 1024 conv2d_22[0][0] __________________________________________________________________________________________________ leaky_re_lu_22 (LeakyReLU) (None, None, None, 2 0 batch_normalization_22[0][0] __________________________________________________________________________________________________ add_9 (Add) (None, None, None, 2 0 add_8[0][0] leaky_re_lu_22[0][0] __________________________________________________________________________________________________ conv2d_23 (Conv2D) (None, None, None, 1 32768 add_9[0][0] __________________________________________________________________________________________________ batch_normalization_23 (BatchNo (None, None, None, 1 512 conv2d_23[0][0] __________________________________________________________________________________________________ leaky_re_lu_23 (LeakyReLU) (None, None, None, 1 0 batch_normalization_23[0][0] __________________________________________________________________________________________________ conv2d_24 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_23[0][0] __________________________________________________________________________________________________ batch_normalization_24 (BatchNo (None, None, None, 2 1024 conv2d_24[0][0] __________________________________________________________________________________________________ leaky_re_lu_24 (LeakyReLU) (None, None, None, 2 0 batch_normalization_24[0][0] __________________________________________________________________________________________________ add_10 (Add) (None, None, None, 2 0 add_9[0][0] leaky_re_lu_24[0][0] __________________________________________________________________________________________________ conv2d_25 (Conv2D) (None, None, None, 1 32768 add_10[0][0] __________________________________________________________________________________________________ batch_normalization_25 (BatchNo (None, None, None, 1 512 conv2d_25[0][0] __________________________________________________________________________________________________ leaky_re_lu_25 (LeakyReLU) (None, None, None, 1 0 batch_normalization_25[0][0] __________________________________________________________________________________________________ conv2d_26 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_25[0][0] __________________________________________________________________________________________________ batch_normalization_26 (BatchNo (None, None, None, 2 1024 conv2d_26[0][0] __________________________________________________________________________________________________ leaky_re_lu_26 (LeakyReLU) (None, None, None, 2 0 batch_normalization_26[0][0] __________________________________________________________________________________________________ add_11 (Add) (None, None, None, 2 0 add_10[0][0] leaky_re_lu_26[0][0] __________________________________________________________________________________________________ zero_padding2d_4 (ZeroPadding2D (None, None, None, 2 0 add_11[0][0] __________________________________________________________________________________________________ conv2d_27 (Conv2D) (None, None, None, 5 1179648 zero_padding2d_4[0][0] __________________________________________________________________________________________________ batch_normalization_27 (BatchNo (None, None, None, 5 2048 conv2d_27[0][0] __________________________________________________________________________________________________ leaky_re_lu_27 (LeakyReLU) (None, None, None, 5 0 batch_normalization_27[0][0] __________________________________________________________________________________________________ conv2d_28 (Conv2D) (None, None, None, 2 131072 leaky_re_lu_27[0][0] __________________________________________________________________________________________________ batch_normalization_28 (BatchNo (None, None, None, 2 1024 conv2d_28[0][0] __________________________________________________________________________________________________ leaky_re_lu_28 (LeakyReLU) (None, None, None, 2 0 batch_normalization_28[0][0] __________________________________________________________________________________________________ conv2d_29 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_28[0][0] __________________________________________________________________________________________________ batch_normalization_29 (BatchNo (None, None, None, 5 2048 conv2d_29[0][0] __________________________________________________________________________________________________ leaky_re_lu_29 (LeakyReLU) (None, None, None, 5 0 batch_normalization_29[0][0] __________________________________________________________________________________________________ add_12 (Add) (None, None, None, 5 0 leaky_re_lu_27[0][0] leaky_re_lu_29[0][0] __________________________________________________________________________________________________ conv2d_30 (Conv2D) (None, None, None, 2 131072 add_12[0][0] __________________________________________________________________________________________________ batch_normalization_30 (BatchNo (None, None, None, 2 1024 conv2d_30[0][0] __________________________________________________________________________________________________ leaky_re_lu_30 (LeakyReLU) (None, None, None, 2 0 batch_normalization_30[0][0] __________________________________________________________________________________________________ conv2d_31 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_30[0][0] __________________________________________________________________________________________________ batch_normalization_31 (BatchNo (None, None, None, 5 2048 conv2d_31[0][0] __________________________________________________________________________________________________ leaky_re_lu_31 (LeakyReLU) (None, None, None, 5 0 batch_normalization_31[0][0] __________________________________________________________________________________________________ add_13 (Add) (None, None, None, 5 0 add_12[0][0] leaky_re_lu_31[0][0] __________________________________________________________________________________________________ conv2d_32 (Conv2D) (None, None, None, 2 131072 add_13[0][0] __________________________________________________________________________________________________ batch_normalization_32 (BatchNo (None, None, None, 2 1024 conv2d_32[0][0] __________________________________________________________________________________________________ leaky_re_lu_32 (LeakyReLU) (None, None, None, 2 0 batch_normalization_32[0][0] __________________________________________________________________________________________________ conv2d_33 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_32[0][0] __________________________________________________________________________________________________ batch_normalization_33 (BatchNo (None, None, None, 5 2048 conv2d_33[0][0] __________________________________________________________________________________________________ leaky_re_lu_33 (LeakyReLU) (None, None, None, 5 0 batch_normalization_33[0][0] __________________________________________________________________________________________________ add_14 (Add) (None, None, None, 5 0 add_13[0][0] leaky_re_lu_33[0][0] __________________________________________________________________________________________________ conv2d_34 (Conv2D) (None, None, None, 2 131072 add_14[0][0] __________________________________________________________________________________________________ batch_normalization_34 (BatchNo (None, None, None, 2 1024 conv2d_34[0][0] __________________________________________________________________________________________________ leaky_re_lu_34 (LeakyReLU) (None, None, None, 2 0 batch_normalization_34[0][0] __________________________________________________________________________________________________ conv2d_35 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_34[0][0] __________________________________________________________________________________________________ batch_normalization_35 (BatchNo (None, None, None, 5 2048 conv2d_35[0][0] __________________________________________________________________________________________________ leaky_re_lu_35 (LeakyReLU) (None, None, None, 5 0 batch_normalization_35[0][0] __________________________________________________________________________________________________ add_15 (Add) (None, None, None, 5 0 add_14[0][0] leaky_re_lu_35[0][0] __________________________________________________________________________________________________ conv2d_36 (Conv2D) (None, None, None, 2 131072 add_15[0][0] __________________________________________________________________________________________________ batch_normalization_36 (BatchNo (None, None, None, 2 1024 conv2d_36[0][0] __________________________________________________________________________________________________ leaky_re_lu_36 (LeakyReLU) (None, None, None, 2 0 batch_normalization_36[0][0] __________________________________________________________________________________________________ conv2d_37 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_36[0][0] __________________________________________________________________________________________________ batch_normalization_37 (BatchNo (None, None, None, 5 2048 conv2d_37[0][0] __________________________________________________________________________________________________ leaky_re_lu_37 (LeakyReLU) (None, None, None, 5 0 batch_normalization_37[0][0] __________________________________________________________________________________________________ add_16 (Add) (None, None, None, 5 0 add_15[0][0] leaky_re_lu_37[0][0] __________________________________________________________________________________________________ conv2d_38 (Conv2D) (None, None, None, 2 131072 add_16[0][0] __________________________________________________________________________________________________ batch_normalization_38 (BatchNo (None, None, None, 2 1024 conv2d_38[0][0] __________________________________________________________________________________________________ leaky_re_lu_38 (LeakyReLU) (None, None, None, 2 0 batch_normalization_38[0][0] __________________________________________________________________________________________________ conv2d_39 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_38[0][0] __________________________________________________________________________________________________ batch_normalization_39 (BatchNo (None, None, None, 5 2048 conv2d_39[0][0] __________________________________________________________________________________________________ leaky_re_lu_39 (LeakyReLU) (None, None, None, 5 0 batch_normalization_39[0][0] __________________________________________________________________________________________________ add_17 (Add) (None, None, None, 5 0 add_16[0][0] leaky_re_lu_39[0][0] __________________________________________________________________________________________________ conv2d_40 (Conv2D) (None, None, None, 2 131072 add_17[0][0] __________________________________________________________________________________________________ batch_normalization_40 (BatchNo (None, None, None, 2 1024 conv2d_40[0][0] __________________________________________________________________________________________________ leaky_re_lu_40 (LeakyReLU) (None, None, None, 2 0 batch_normalization_40[0][0] __________________________________________________________________________________________________ conv2d_41 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_40[0][0] __________________________________________________________________________________________________ batch_normalization_41 (BatchNo (None, None, None, 5 2048 conv2d_41[0][0] __________________________________________________________________________________________________ leaky_re_lu_41 (LeakyReLU) (None, None, None, 5 0 batch_normalization_41[0][0] __________________________________________________________________________________________________ add_18 (Add) (None, None, None, 5 0 add_17[0][0] leaky_re_lu_41[0][0] __________________________________________________________________________________________________ conv2d_42 (Conv2D) (None, None, None, 2 131072 add_18[0][0] __________________________________________________________________________________________________ batch_normalization_42 (BatchNo (None, None, None, 2 1024 conv2d_42[0][0] __________________________________________________________________________________________________ leaky_re_lu_42 (LeakyReLU) (None, None, None, 2 0 batch_normalization_42[0][0] __________________________________________________________________________________________________ conv2d_43 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_42[0][0] __________________________________________________________________________________________________ batch_normalization_43 (BatchNo (None, None, None, 5 2048 conv2d_43[0][0] __________________________________________________________________________________________________ leaky_re_lu_43 (LeakyReLU) (None, None, None, 5 0 batch_normalization_43[0][0] __________________________________________________________________________________________________ add_19 (Add) (None, None, None, 5 0 add_18[0][0] leaky_re_lu_43[0][0] __________________________________________________________________________________________________ zero_padding2d_5 (ZeroPadding2D (None, None, None, 5 0 add_19[0][0] __________________________________________________________________________________________________ conv2d_44 (Conv2D) (None, None, None, 1 4718592 zero_padding2d_5[0][0] __________________________________________________________________________________________________ batch_normalization_44 (BatchNo (None, None, None, 1 4096 conv2d_44[0][0] __________________________________________________________________________________________________ leaky_re_lu_44 (LeakyReLU) (None, None, None, 1 0 batch_normalization_44[0][0] __________________________________________________________________________________________________ conv2d_45 (Conv2D) (None, None, None, 5 524288 leaky_re_lu_44[0][0] __________________________________________________________________________________________________ batch_normalization_45 (BatchNo (None, None, None, 5 2048 conv2d_45[0][0] __________________________________________________________________________________________________ leaky_re_lu_45 (LeakyReLU) (None, None, None, 5 0 batch_normalization_45[0][0] __________________________________________________________________________________________________ conv2d_46 (Conv2D) (None, None, None, 1 4718592 leaky_re_lu_45[0][0] __________________________________________________________________________________________________ batch_normalization_46 (BatchNo (None, None, None, 1 4096 conv2d_46[0][0] __________________________________________________________________________________________________ leaky_re_lu_46 (LeakyReLU) (None, None, None, 1 0 batch_normalization_46[0][0] __________________________________________________________________________________________________ add_20 (Add) (None, None, None, 1 0 leaky_re_lu_44[0][0] leaky_re_lu_46[0][0] __________________________________________________________________________________________________ conv2d_47 (Conv2D) (None, None, None, 5 524288 add_20[0][0] __________________________________________________________________________________________________ batch_normalization_47 (BatchNo (None, None, None, 5 2048 conv2d_47[0][0] __________________________________________________________________________________________________ leaky_re_lu_47 (LeakyReLU) (None, None, None, 5 0 batch_normalization_47[0][0] __________________________________________________________________________________________________ conv2d_48 (Conv2D) (None, None, None, 1 4718592 leaky_re_lu_47[0][0] __________________________________________________________________________________________________ batch_normalization_48 (BatchNo (None, None, None, 1 4096 conv2d_48[0][0] __________________________________________________________________________________________________ leaky_re_lu_48 (LeakyReLU) (None, None, None, 1 0 batch_normalization_48[0][0] __________________________________________________________________________________________________ add_21 (Add) (None, None, None, 1 0 add_20[0][0] leaky_re_lu_48[0][0] __________________________________________________________________________________________________ conv2d_49 (Conv2D) (None, None, None, 5 524288 add_21[0][0] __________________________________________________________________________________________________ batch_normalization_49 (BatchNo (None, None, None, 5 2048 conv2d_49[0][0] __________________________________________________________________________________________________ leaky_re_lu_49 (LeakyReLU) (None, None, None, 5 0 batch_normalization_49[0][0] __________________________________________________________________________________________________ conv2d_50 (Conv2D) (None, None, None, 1 4718592 leaky_re_lu_49[0][0] __________________________________________________________________________________________________ batch_normalization_50 (BatchNo (None, None, None, 1 4096 conv2d_50[0][0] __________________________________________________________________________________________________ leaky_re_lu_50 (LeakyReLU) (None, None, None, 1 0 batch_normalization_50[0][0] __________________________________________________________________________________________________ add_22 (Add) (None, None, None, 1 0 add_21[0][0] leaky_re_lu_50[0][0] __________________________________________________________________________________________________ conv2d_51 (Conv2D) (None, None, None, 5 524288 add_22[0][0] __________________________________________________________________________________________________ batch_normalization_51 (BatchNo (None, None, None, 5 2048 conv2d_51[0][0] __________________________________________________________________________________________________ leaky_re_lu_51 (LeakyReLU) (None, None, None, 5 0 batch_normalization_51[0][0] __________________________________________________________________________________________________ conv2d_52 (Conv2D) (None, None, None, 1 4718592 leaky_re_lu_51[0][0] __________________________________________________________________________________________________ batch_normalization_52 (BatchNo (None, None, None, 1 4096 conv2d_52[0][0] __________________________________________________________________________________________________ leaky_re_lu_52 (LeakyReLU) (None, None, None, 1 0 batch_normalization_52[0][0] __________________________________________________________________________________________________ add_23 (Add) (None, None, None, 1 0 add_22[0][0] leaky_re_lu_52[0][0] __________________________________________________________________________________________________ conv2d_53 (Conv2D) (None, None, None, 5 524288 add_23[0][0] __________________________________________________________________________________________________ batch_normalization_53 (BatchNo (None, None, None, 5 2048 conv2d_53[0][0] __________________________________________________________________________________________________ leaky_re_lu_53 (LeakyReLU) (None, None, None, 5 0 batch_normalization_53[0][0] __________________________________________________________________________________________________ conv2d_54 (Conv2D) (None, None, None, 1 4718592 leaky_re_lu_53[0][0] __________________________________________________________________________________________________ batch_normalization_54 (BatchNo (None, None, None, 1 4096 conv2d_54[0][0] __________________________________________________________________________________________________ leaky_re_lu_54 (LeakyReLU) (None, None, None, 1 0 batch_normalization_54[0][0] __________________________________________________________________________________________________ conv2d_55 (Conv2D) (None, None, None, 5 524288 leaky_re_lu_54[0][0] __________________________________________________________________________________________________ batch_normalization_55 (BatchNo (None, None, None, 5 2048 conv2d_55[0][0] __________________________________________________________________________________________________ leaky_re_lu_55 (LeakyReLU) (None, None, None, 5 0 batch_normalization_55[0][0] __________________________________________________________________________________________________ conv2d_56 (Conv2D) (None, None, None, 1 4718592 leaky_re_lu_55[0][0] __________________________________________________________________________________________________ batch_normalization_56 (BatchNo (None, None, None, 1 4096 conv2d_56[0][0] __________________________________________________________________________________________________ leaky_re_lu_56 (LeakyReLU) (None, None, None, 1 0 batch_normalization_56[0][0] __________________________________________________________________________________________________ conv2d_57 (Conv2D) (None, None, None, 5 524288 leaky_re_lu_56[0][0] __________________________________________________________________________________________________ batch_normalization_57 (BatchNo (None, None, None, 5 2048 conv2d_57[0][0] __________________________________________________________________________________________________ leaky_re_lu_57 (LeakyReLU) (None, None, None, 5 0 batch_normalization_57[0][0] __________________________________________________________________________________________________ conv2d_60 (Conv2D) (None, None, None, 2 131072 leaky_re_lu_57[0][0] __________________________________________________________________________________________________ batch_normalization_59 (BatchNo (None, None, None, 2 1024 conv2d_60[0][0] __________________________________________________________________________________________________ leaky_re_lu_59 (LeakyReLU) (None, None, None, 2 0 batch_normalization_59[0][0] __________________________________________________________________________________________________ up_sampling2d_1 (UpSampling2D) (None, None, None, 2 0 leaky_re_lu_59[0][0] __________________________________________________________________________________________________ concatenate_1 (Concatenate) (None, None, None, 7 0 up_sampling2d_1[0][0] add_19[0][0] __________________________________________________________________________________________________ conv2d_61 (Conv2D) (None, None, None, 2 196608 concatenate_1[0][0] __________________________________________________________________________________________________ batch_normalization_60 (BatchNo (None, None, None, 2 1024 conv2d_61[0][0] __________________________________________________________________________________________________ leaky_re_lu_60 (LeakyReLU) (None, None, None, 2 0 batch_normalization_60[0][0] __________________________________________________________________________________________________ conv2d_62 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_60[0][0] __________________________________________________________________________________________________ batch_normalization_61 (BatchNo (None, None, None, 5 2048 conv2d_62[0][0] __________________________________________________________________________________________________ leaky_re_lu_61 (LeakyReLU) (None, None, None, 5 0 batch_normalization_61[0][0] __________________________________________________________________________________________________ conv2d_63 (Conv2D) (None, None, None, 2 131072 leaky_re_lu_61[0][0] __________________________________________________________________________________________________ batch_normalization_62 (BatchNo (None, None, None, 2 1024 conv2d_63[0][0] __________________________________________________________________________________________________ leaky_re_lu_62 (LeakyReLU) (None, None, None, 2 0 batch_normalization_62[0][0] __________________________________________________________________________________________________ conv2d_64 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_62[0][0] __________________________________________________________________________________________________ batch_normalization_63 (BatchNo (None, None, None, 5 2048 conv2d_64[0][0] __________________________________________________________________________________________________ leaky_re_lu_63 (LeakyReLU) (None, None, None, 5 0 batch_normalization_63[0][0] __________________________________________________________________________________________________ conv2d_65 (Conv2D) (None, None, None, 2 131072 leaky_re_lu_63[0][0] __________________________________________________________________________________________________ batch_normalization_64 (BatchNo (None, None, None, 2 1024 conv2d_65[0][0] __________________________________________________________________________________________________ leaky_re_lu_64 (LeakyReLU) (None, None, None, 2 0 batch_normalization_64[0][0] __________________________________________________________________________________________________ conv2d_68 (Conv2D) (None, None, None, 1 32768 leaky_re_lu_64[0][0] __________________________________________________________________________________________________ batch_normalization_66 (BatchNo (None, None, None, 1 512 conv2d_68[0][0] __________________________________________________________________________________________________ leaky_re_lu_66 (LeakyReLU) (None, None, None, 1 0 batch_normalization_66[0][0] __________________________________________________________________________________________________ up_sampling2d_2 (UpSampling2D) (None, None, None, 1 0 leaky_re_lu_66[0][0] __________________________________________________________________________________________________ concatenate_2 (Concatenate) (None, None, None, 3 0 up_sampling2d_2[0][0] add_11[0][0] __________________________________________________________________________________________________ conv2d_69 (Conv2D) (None, None, None, 1 49152 concatenate_2[0][0] __________________________________________________________________________________________________ batch_normalization_67 (BatchNo (None, None, None, 1 512 conv2d_69[0][0] __________________________________________________________________________________________________ leaky_re_lu_67 (LeakyReLU) (None, None, None, 1 0 batch_normalization_67[0][0] __________________________________________________________________________________________________ conv2d_70 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_67[0][0] __________________________________________________________________________________________________ batch_normalization_68 (BatchNo (None, None, None, 2 1024 conv2d_70[0][0] __________________________________________________________________________________________________ leaky_re_lu_68 (LeakyReLU) (None, None, None, 2 0 batch_normalization_68[0][0] __________________________________________________________________________________________________ conv2d_71 (Conv2D) (None, None, None, 1 32768 leaky_re_lu_68[0][0] __________________________________________________________________________________________________ batch_normalization_69 (BatchNo (None, None, None, 1 512 conv2d_71[0][0] __________________________________________________________________________________________________ leaky_re_lu_69 (LeakyReLU) (None, None, None, 1 0 batch_normalization_69[0][0] __________________________________________________________________________________________________ conv2d_72 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_69[0][0] __________________________________________________________________________________________________ batch_normalization_70 (BatchNo (None, None, None, 2 1024 conv2d_72[0][0] __________________________________________________________________________________________________ leaky_re_lu_70 (LeakyReLU) (None, None, None, 2 0 batch_normalization_70[0][0] __________________________________________________________________________________________________ conv2d_73 (Conv2D) (None, None, None, 1 32768 leaky_re_lu_70[0][0] __________________________________________________________________________________________________ batch_normalization_71 (BatchNo (None, None, None, 1 512 conv2d_73[0][0] __________________________________________________________________________________________________ leaky_re_lu_71 (LeakyReLU) (None, None, None, 1 0 batch_normalization_71[0][0] __________________________________________________________________________________________________ conv2d_58 (Conv2D) (None, None, None, 1 4718592 leaky_re_lu_57[0][0] __________________________________________________________________________________________________ conv2d_66 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_64[0][0] __________________________________________________________________________________________________ conv2d_74 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_71[0][0] __________________________________________________________________________________________________ batch_normalization_58 (BatchNo (None, None, None, 1 4096 conv2d_58[0][0] __________________________________________________________________________________________________ batch_normalization_65 (BatchNo (None, None, None, 5 2048 conv2d_66[0][0] __________________________________________________________________________________________________ batch_normalization_72 (BatchNo (None, None, None, 2 1024 conv2d_74[0][0] __________________________________________________________________________________________________ leaky_re_lu_58 (LeakyReLU) (None, None, None, 1 0 batch_normalization_58[0][0] __________________________________________________________________________________________________ leaky_re_lu_65 (LeakyReLU) (None, None, None, 5 0 batch_normalization_65[0][0] __________________________________________________________________________________________________ leaky_re_lu_72 (LeakyReLU) (None, None, None, 2 0 batch_normalization_72[0][0] __________________________________________________________________________________________________ conv2d_59 (Conv2D) (None, None, None, 2 261375 leaky_re_lu_58[0][0] __________________________________________________________________________________________________ conv2d_67 (Conv2D) (None, None, None, 2 130815 leaky_re_lu_65[0][0] __________________________________________________________________________________________________ conv2d_75 (Conv2D) (None, None, None, 2 65535 leaky_re_lu_72[0][0] ================================================================================================== Total params: 62,001,757 Trainable params: 61,949,149 Non-trainable params: 52,608 __________________________________________________________________________________________________ None Saved Keras model to model_data/yolo.h5 Read 62001757 of 62001757.0 from Darknet weights.
Below, we'll call a "self-contained" Python script that initiates training our model on our custom dataset.
Pay notable attention to:
- setting the paths for our
annotation_path
,classes_path
,class_names
. If you move the Roboflow data location, you'll need to update these. val_split
dictates the size of our training data relative to our taining datalr=1e-3
to set the learning rate of the model. Smaller optimizes more slowly but potentially more precisely.batch_size
for the number of images trained per batch-
epoch
insidemodel.fit_generator()
sets the number training epochs to increase/decrease training examples (and time)
Consider reading the YOLOv3 paper here.
"""
Self-contained Python script to train YOLOv3 on your own dataset
"""
import numpy as np
import keras.backend as K
from keras.layers import Input, Lambda
from keras.models import Model
from keras.optimizers import Adam
from keras.callbacks import TensorBoard, ModelCheckpoint, ReduceLROnPlateau, EarlyStopping
from yolo3.model import preprocess_true_boxes, yolo_body, tiny_yolo_body, yolo_loss
from yolo3.utils import get_random_data
def _main():
annotation_path = '_annotations.txt' # path to Roboflow data annotations
log_dir = 'logs/000/' # where we're storing our logs
classes_path = '_classes.txt' # path to Roboflow class names
anchors_path = 'model_data/yolo_anchors.txt'
class_names = get_classes(classes_path)
print("-------------------CLASS NAMES-------------------")
print(class_names)
print("-------------------CLASS NAMES-------------------")
num_classes = len(class_names)
anchors = get_anchors(anchors_path)
input_shape = (416,416) # multiple of 32, hw
is_tiny_version = len(anchors)==6 # default setting
if is_tiny_version:
model = create_tiny_model(input_shape, anchors, num_classes,
freeze_body=2, weights_path='model_data/tiny_yolo_weights.h5')
else:
model = create_model(input_shape, anchors, num_classes,
freeze_body=2, weights_path='model_data/yolo.h5') # make sure you know what you freeze
logging = TensorBoard(log_dir=log_dir)
checkpoint = ModelCheckpoint(log_dir + 'ep{epoch:03d}-loss{loss:.3f}-val_loss{val_loss:.3f}.h5',
monitor='val_loss', save_weights_only=True, save_best_only=True, period=3)
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=3, verbose=1)
early_stopping = EarlyStopping(monitor='val_loss', min_delta=0, patience=10, verbose=1)
val_split = 0.2 # set the size of the validation set
with open(annotation_path) as f:
lines = f.readlines()
np.random.seed(10101)
np.random.shuffle(lines)
np.random.seed(None)
num_val = int(len(lines)*val_split)
num_train = len(lines) - num_val
# Train with frozen layers first, to get a stable loss.
# Adjust num epochs to your dataset. This step is enough to obtain a not bad model.
if True:
model.compile(optimizer=Adam(lr=1e-3), loss={
# use custom yolo_loss Lambda layer.
'yolo_loss': lambda y_true, y_pred: y_pred})
batch_size = 32
print('Train on {} samples, val on {} samples, with batch size {}.'.format(num_train, num_val, batch_size))
model.fit_generator(data_generator_wrapper(lines[:num_train], batch_size, input_shape, anchors, num_classes),
steps_per_epoch=max(1, num_train//batch_size),
validation_data=data_generator_wrapper(lines[num_train:], batch_size, input_shape, anchors, num_classes),
validation_steps=max(1, num_val//batch_size),
epochs=500,
initial_epoch=0,
callbacks=[logging, checkpoint])
model.save_weights(log_dir + 'trained_weights_stage_1.h5')
# Unfreeze and continue training, to fine-tune.
# Train longer if the result is not good.
if True:
for i in range(len(model.layers)):
model.layers[i].trainable = True
model.compile(optimizer=Adam(lr=1e-4), loss={'yolo_loss': lambda y_true, y_pred: y_pred}) # recompile to apply the change
print('Unfreeze all of the layers.')
batch_size = 32 # note that more GPU memory is required after unfreezing the body
print('Train on {} samples, val on {} samples, with batch size {}.'.format(num_train, num_val, batch_size))
model.fit_generator(data_generator_wrapper(lines[:num_train], batch_size, input_shape, anchors, num_classes),
steps_per_epoch=max(1, num_train//batch_size),
validation_data=data_generator_wrapper(lines[num_train:], batch_size, input_shape, anchors, num_classes),
validation_steps=max(1, num_val//batch_size),
epochs=100,
initial_epoch=50,
callbacks=[logging, checkpoint, reduce_lr, early_stopping])
model.save_weights(log_dir + 'trained_weights_final.h5')
# Further training if needed.
def get_classes(classes_path):
'''loads the classes'''
with open(classes_path) as f:
class_names = f.readlines()
class_names = [c.strip() for c in class_names]
return class_names
def get_anchors(anchors_path):
'''loads the anchors from a file'''
with open(anchors_path) as f:
anchors = f.readline()
anchors = [float(x) for x in anchors.split(',')]
return np.array(anchors).reshape(-1, 2)
def create_model(input_shape, anchors, num_classes, load_pretrained=True, freeze_body=2,
weights_path='model_data/yolo.h5'):
'''create the training model'''
K.clear_session() # get a new session
image_input = Input(shape=(None, None, 3))
h, w = input_shape
num_anchors = len(anchors)
y_true = [Input(shape=(h//{0:32, 1:16, 2:8}[l], w//{0:32, 1:16, 2:8}[l], \
num_anchors//3, num_classes+5)) for l in range(3)]
model_body = yolo_body(image_input, num_anchors//3, num_classes)
print('Create YOLOv3 model with {} anchors and {} classes.'.format(num_anchors, num_classes))
if load_pretrained:
model_body.load_weights(weights_path, by_name=True, skip_mismatch=True)
print('Load weights {}.'.format(weights_path))
if freeze_body in [1, 2]:
# Freeze darknet53 body or freeze all but 3 output layers.
num = (185, len(model_body.layers)-3)[freeze_body-1]
for i in range(num): model_body.layers[i].trainable = False
print('Freeze the first {} layers of total {} layers.'.format(num, len(model_body.layers)))
model_loss = Lambda(yolo_loss, output_shape=(1,), name='yolo_loss',
arguments={'anchors': anchors, 'num_classes': num_classes, 'ignore_thresh': 0.5})(
[*model_body.output, *y_true])
model = Model([model_body.input, *y_true], model_loss)
return model
def create_tiny_model(input_shape, anchors, num_classes, load_pretrained=True, freeze_body=2,
weights_path='model_data/tiny_yolo_weights.h5'):
'''create the training model, for Tiny YOLOv3'''
K.clear_session() # get a new session
image_input = Input(shape=(None, None, 3))
h, w = input_shape
num_anchors = len(anchors)
y_true = [Input(shape=(h//{0:32, 1:16}[l], w//{0:32, 1:16}[l], \
num_anchors//2, num_classes+5)) for l in range(2)]
model_body = tiny_yolo_body(image_input, num_anchors//2, num_classes)
print('Create Tiny YOLOv3 model with {} anchors and {} classes.'.format(num_anchors, num_classes))
if load_pretrained:
model_body.load_weights(weights_path, by_name=True, skip_mismatch=True)
print('Load weights {}.'.format(weights_path))
if freeze_body in [1, 2]:
# Freeze the darknet body or freeze all but 2 output layers.
num = (20, len(model_body.layers)-2)[freeze_body-1]
for i in range(num): model_body.layers[i].trainable = False
print('Freeze the first {} layers of total {} layers.'.format(num, len(model_body.layers)))
model_loss = Lambda(yolo_loss, output_shape=(1,), name='yolo_loss',
arguments={'anchors': anchors, 'num_classes': num_classes, 'ignore_thresh': 0.7})(
[*model_body.output, *y_true])
model = Model([model_body.input, *y_true], model_loss)
return model
def data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes):
'''data generator for fit_generator'''
n = len(annotation_lines)
i = 0
while True:
image_data = []
box_data = []
for b in range(batch_size):
if i==0:
np.random.shuffle(annotation_lines)
image, box = get_random_data(annotation_lines[i], input_shape, random=True)
image_data.append(image)
box_data.append(box)
i = (i+1) % n
image_data = np.array(image_data)
box_data = np.array(box_data)
y_true = preprocess_true_boxes(box_data, input_shape, anchors, num_classes)
yield [image_data, *y_true], np.zeros(batch_size)
def data_generator_wrapper(annotation_lines, batch_size, input_shape, anchors, num_classes):
n = len(annotation_lines)
if n==0 or batch_size<=0: return None
return data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes)
if __name__ == '__main__':
_main()
Using TensorFlow backend.
[0;31m---------------------------------------------------------------------------[0m [0;31mFileNotFoundError[0m Traceback (most recent call last) [0;32m<ipython-input-18-fd737c45ef07>[0m in [0;36m<module>[0;34m()[0m [1;32m 189[0m [0;34m[0m[0m [1;32m 190[0m [0;32mif[0m [0m__name__[0m [0;34m==[0m [0;34m'__main__'[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [0;32m--> 191[0;31m [0m_main[0m[0;34m([0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0m [0;32m<ipython-input-18-fd737c45ef07>[0m in [0;36m_main[0;34m()[0m [1;32m 19[0m [0mclasses_path[0m [0;34m=[0m [0;34m'_classes.txt'[0m [0;31m# path to Roboflow class names[0m[0;34m[0m[0;34m[0m[0m [1;32m 20[0m [0manchors_path[0m [0;34m=[0m [0;34m'model_data/yolo_anchors.txt'[0m[0;34m[0m[0;34m[0m[0m [0;32m---> 21[0;31m [0mclass_names[0m [0;34m=[0m [0mget_classes[0m[0;34m([0m[0mclasses_path[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 22[0m [0mprint[0m[0;34m([0m[0;34m"-------------------CLASS NAMES-------------------"[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 23[0m [0mprint[0m[0;34m([0m[0mclass_names[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0;32m<ipython-input-18-fd737c45ef07>[0m in [0;36mget_classes[0;34m(classes_path)[0m [1;32m 93[0m [0;32mdef[0m [0mget_classes[0m[0;34m([0m[0mclasses_path[0m[0;34m)[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [1;32m 94[0m [0;34m'''loads the classes'''[0m[0;34m[0m[0;34m[0m[0m [0;32m---> 95[0;31m [0;32mwith[0m [0mopen[0m[0;34m([0m[0mclasses_path[0m[0;34m)[0m [0;32mas[0m [0mf[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 96[0m [0mclass_names[0m [0;34m=[0m [0mf[0m[0;34m.[0m[0mreadlines[0m[0;34m([0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 97[0m [0mclass_names[0m [0;34m=[0m [0;34m[[0m[0mc[0m[0;34m.[0m[0mstrip[0m[0;34m([0m[0;34m)[0m [0;32mfor[0m [0mc[0m [0;32min[0m [0mclass_names[0m[0;34m][0m[0;34m[0m[0;34m[0m[0m [0;31mFileNotFoundError[0m: [Errno 2] No such file or directory: '_classes.txt'
## can call this cell instead of the above
# !python train.py
Use our model for inference
For predictions, we'll call a a Python script called yolo_video.py
with required arguments for our use case: a path to our specific first stage trained weights (see our blog for why we're using only stage one), a path to our custom class names, and a flag to specify we're using images.
Additional arguments for yolo_video.py
are as follows:
usage: yolo_video.py [-h] [--model MODEL] [--anchors ANCHORS]
[--classes CLASSES] [--gpu_num GPU_NUM] [--image]
[--input] [--output]
positional arguments:
--input Video input path
--output Video output path
optional arguments:
-h, --help show this help message and exit
--model MODEL path to model weight file, default model_data/yolo.h5
--anchors ANCHORS path to anchor definitions, default
model_data/yolo_anchors.txt
--classes CLASSES path to class definitions, default
model_data/coco_classes.txt
--gpu_num GPU_NUM Number of GPU to use, default 1
--image Image detection mode, will ignore all positional arguments
!python yolo_video.py --model="./logs/000/trained_weights_stage_1.h5" --classes="_classes.txt" --image
For input image names into the above, consider trying the following:
00a7a49c47d51fd16a4cbb17e2d2cf86.jpg
# white-king works! + knight015d0d7ff365f0b7492ff079c8c7d56c.jpg
# black-queen mixes up176b28b5c417f39a9e5d37545fca5b4c.jpg
# finds only five4673f994f60a2ea7afdddc1b752947c0.jpg
# white-rook (thinks king)5ca7f0cb1c500554e65ad031190f8e9f.jpg
# white-pawn (missed white-king)fbf15139f38a46e02b5f4061c0c9b08f.jpg
# black-king success!
You can view these images in your Colab notebook by clicking on the image name in the expanded left-hand panel (Files → keras-yolo3 → IMG_NAME ).
Move currently trained model to GDrive
Optionally, you may want to save the new weights that your model trained so that the next time you run this notebook, you can either skip training and use these weights for inference or begin training where you left off with this weights file.
Following the below will link your Colab notebook to your Google Drive, and save the weights (named as the current time you saved them to enforce a unique file name) in your Drive folder.
# mount Google Drive
from google.colab import drive
drive.mount('/content/drive')
# create a copy of the weights file with a datetime
# and move that file to your own Drive
%cp ./logs/000/trained_weights_stage_1.h5 ./logs/000/trained_weights_stage_1_$(date +%F-%H:%M).h5
%mv ./logs/000/trained_weights_stage_1_$(date +%F-%H:%M).h5 /content/drive/My\ Drive/