Tensorflow 2.0 is required, so if you don't have it, uncomment and run the following command
#!pip install tensorflow --upgrade
Download the weight file for YOLOv3 from their official website
!wget https://pjreddie.com/media/files/yolov3.weights
Prepare the folder for storing the weights
!rm -rf checkpoints
!mkdir checkpoints
Import all required libraries
import cv2
import numpy as np
import tensorflow as tf
from absl import logging
from itertools import repeat
from tensorflow.keras import Model
from tensorflow.keras.layers import Add, Concatenate, Lambda
from tensorflow.keras.layers import Conv2D, Input, LeakyReLU
from tensorflow.keras.layers import MaxPool2D, UpSampling2D, ZeroPadding2D
from tensorflow.keras.regularizers import l2
from tensorflow.keras.losses import binary_crossentropy
from tensorflow.keras.losses import sparse_categorical_crossentropy
Check TensorFlow version. It should be 2.0.
print(tf.__version__)
Define some imporant value which we will use later
yolo_iou_threshold = 0.6 # iou threshold
yolo_score_threshold = 0.6 # score threshold
weightsyolov3 = 'yolov3.weights' # path to weights file
weights= 'checkpoints/yolov3.tf' # path to checkpoints file
size= 416 #resize images to\
checkpoints = 'checkpoints/yolov3.tf'
num_classes = 80 # number of classes in the model
List of layers in YOLOv3 FCN — Fully Convolutional Network
YOLO_V3_LAYERS = [
'yolo_darknet',
'yolo_conv_0',
'yolo_output_0',
'yolo_conv_1',
'yolo_output_1',
'yolo_conv_2',
'yolo_output_2',
]