📚
DLIP
  • Introduction
  • Prerequisite
  • Image Processing Basics
    • Notes
      • Thresholding
      • Spatial Filtering
      • Masking with Bitwise Operation
      • Model n Calibration
    • Tutorial
      • Tutorial: Install OpenCV C++
      • Tutorial: Create OpenCV Project
      • Tutorial: C++ basics
      • Tutorial: OpenCV Basics
      • Tutorial: Image Watch for Debugging
      • Tutorial: Spatial Filter
      • Tutorial: Thresholding and Morphology
      • Tutorial: Camera Calibration
      • Tutorial: Color Image Processing
      • Tutorial: Edge Line Circle Detection
      • Tutorial: Corner Detection and Optical Flow
      • Tutorial: OpenCV C++ Cheatsheet
      • Tutorial: Installation for Py OpenCV
      • Tutorial: OpenCv (Python) Basics
    • LAB
      • Lab Report Template
      • Lab Report Grading Criteria
      • LAB Report Instruction
      • LAB: Grayscale Image Segmentation
        • LAB: Grayscale Image Segmentation -Gear
        • LAB: Grayscale Image Segmentation - Bolt and Nut
      • LAB: Color Image Segmentation
        • LAB: Facial Temperature Measurement with IR images
        • LAB: Magic Cloak
      • LAB: Straight Lane Detection and Departure Warning
      • LAB: Dimension Measurement with 2D camera
      • LAB: Tension Detection of Rolling Metal Sheet
  • Deep Learning for Perception
    • Notes
      • Lane Detection with Deep Learning
      • Overview of Deep Learning
        • Object Detection
        • Deep Learning Basics: Introduction
        • Deep Learning State of the Art
        • CNN, Object Detection
      • Perceptron
      • Activation Function
      • Optimization
      • Convolution
      • CNN Overview
      • Evaluation Metric
      • LossFunction Regularization
      • Bias vs Variance
      • BottleNeck Unit
      • Object Detection
      • DL Techniques
        • Technical Strategy by A.Ng
    • Tutorial - PyTorch
      • Tutorial: Install PyTorch
      • Tutorial: Python Numpy
      • Tutorial: PyTorch Tutorial List
      • Tutorial: PyTorch Example Code
      • Tutorial: Tensorboard in Pytorch
      • Tutorial: YOLO in PyTorch
        • Tutorial: Yolov8 in PyTorch
        • Tutorial: Train Yolo v8 with custom dataset
          • Tutorial: Train Yolo v5 with custom dataset
        • Tutorial: Yolov5 in Pytorch (VS code)
        • Tutorial: Yolov3 in Keras
    • LAB
      • Assignment: CNN Classification
      • Assignment: Object Detection
      • LAB: CNN Object Detection 1
      • LAB: CNN Object Detection 2
      • LAB Grading Criteria
    • Tutorial- Keras
      • Train Dataset
      • Train custom dataset
      • Test model
      • LeNet-5 Tutorial
      • AlexNet Tutorial
      • VGG Tutorial
      • ResNet Tutorial
    • Resource
      • Online Lecture
      • Programming tutorial
      • Books
      • Hardware
      • Dataset
      • Useful sites
  • Must Read Papers
    • AlexNet
    • VGG
    • ResNet
    • R-CNN, Fast-RCNN, Faster-RCNN
    • YOLOv1-3
    • Inception
    • MobileNet
    • SSD
    • ShuffleNet
    • Recent Methods
  • DLIP Project
    • Report Template
    • DLIP 2021 Projects
      • Digital Door Lock Control with Face Recognition
      • People Counting with YOLOv4 and DeepSORT
      • Eye Blinking Detection Alarm
      • Helmet-Detection Using YOLO-V5
      • Mask Detection using YOLOv5
      • Parking Space Management
      • Vehicle, Pedestrian Detection with IR Image
      • Drum Playing Detection
      • Turtle neck measurement program using OpenPose
    • DLIP 2022 Projects
      • BakeryCashier
      • Virtual Mouse
      • Sudoku Program with Hand gesture
      • Exercise Posture Assistance System
      • People Counting Embedded System
      • Turtle neck measurement program using OpenPose
    • DLIP Past Projects
  • Installation Guide
    • Installation Guide for Pytorch
      • Installation Guide 2021
    • Anaconda
    • CUDA cuDNN
      • CUDA 10.2
    • OpenCV
      • OpenCV Install and Setup
        • OpenCV 3.4.13 with VS2019
        • OpenCV3.4.7 VS2017
        • MacOS OpenCV C++ in XCode
      • Python OpenCV
      • MATLAB-OpenCV
    • Framework
      • Keras
      • TensorFlow
        • Cheat Sheet
        • Tutorial
      • PyTorch
    • IDE
      • Visual Studio Community
      • Google Codelab
      • Visual Studio Code
        • Python with VS Code
        • Notebook with VS Code
        • C++ with VS Code
      • Jupyter Notebook
        • Install
        • How to use
    • Ubuntu
      • Ubuntu 18.04 Installation
      • Ubuntu Installation using Docker in Win10
      • Ubuntu Troubleshooting
    • ROS
  • Programming
    • Python_Numpy
      • Python Tutorial - Tips
      • Python Tutorial - For Loop
      • Python Tutorial - List Tuple, Dic, Set
    • Markdown
      • Example: API documentation
    • Github
      • Create account
      • Tutorial: Github basic
      • Tutorial: Github Desktop
    • Keras
      • Tutorial Keras
      • Cheat Sheet
    • PyTorch
      • Cheat Sheet
      • Autograd in PyTorch
      • Simple ConvNet
      • MNIST using LeNet
      • Train ConvNet using CIFAR10
  • Resources
    • Useful Resources
    • Github
Powered by GitBook
On this page
  • Reference
  • Setup
  • Create Virtual Environment (Conda)
  • Clone Git
  • Download the trained weight file
  • Open V.S Code
  • Convert Darknet YOLOv3 to Keras model
  • Run Yolov3 Detection
  • Run Yolov3-Tiny Detection
  • Usage
  • How to train a dataset
  • Prepare the dataset
  • Modify train.py
  • Run Train
  • Evaluate
  • TroubleShooting
  • Problem 1

Was this helpful?

  1. Deep Learning for Perception
  2. Tutorial - PyTorch
  3. Tutorial: YOLO in PyTorch

Tutorial: Yolov3 in Keras

PreviousTutorial: Yolov5 in Pytorch (VS code)NextLAB

Last updated 3 years ago

Was this helpful?

Reference

Github:

Setup

Create Virtual Environment (Conda)

Lets create a virtual environment for YOLOv3.

The requirements are

  • python=3.7.10

  • cudatoolkit=10.0

  • cudnn-7.6.5-cuda10.0_0

  • tensorflow-gpu=1.15.0

  • keras=2.3.1

  • pillow=8.2.0

  • matplotlib=3.3.4

  • opencv=3.4.2

If you have problems when installing opencv packages, use the following commands pip install opencv-python

conda create -n tf115 python=3.7
conda activate tf115

Install the following:

conda install cudatoolkit=10.0
conda install cudnn
conda install tensorflow-gpu=1.15.0
conda install keras=2.3
conda install pillow
conda install matplotlib
conda install opencv

Clone Git

After the installation, activate the virtual environment. We will clone the reference repository to download Yolov3 codes.

Method 1: From conda prompt (in virtual env)

Method 2:

Download zip file from the github and unzip.

Download the trained weight file

After the download, place the weight model file in the same directory of Yolov3.

You can also download it from the conda Prompt as

  • YOLOv3-tiny weights

Open V.S Code

>> code .

You can also run the below codes in the Conda Promt

In VS code, select the virtual environment: F1--> Python Interpreter --> Select Environ.

Convert Darknet YOLOv3 to Keras model

In the terminal of VS code or in Conda Prompt, type:

>> python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5

Run Yolov3 Detection

Copy the test video file in the same directory (Yolov3 directory)

If the video file name is 'test_Video.avi'

>> python yolo_video.py --model .\model_data\yolo.h5 --input .\test_Video.avi

Run Yolov3-Tiny Detection

After downloading yolov3-tiny.weights, Convert it to Keras model and save it as 'yolo-tiny.h5'

 >> python convert.py yolov3-tiny.cfg yolov3-tiny.weights model_data/yolo-tiny.h5

Run Yolo-tiny with the Test video

>> python yolo_video.py --model .\model_data\yolo-tiny.h5 --input .\test_Video.avi

Usage

Use --help to see usage of yolo_video.py:

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

How to train a dataset

Prepare the dataset

For this tutorial, we will use KITTI dataset

  • Class file:

    • Copy the 'kitti_classes.txt' in the folder of `\model_data` folder

Modify train.py

Open 'train.py' file in VS Code\

Go to LIne 16 : def main():. Change the ''annotation' and 'classes-path' to your setting.

def _main(): 
annotation_path = 'train.txt' log_dir = 'logs/000/'
#classes_path = 'model_data/voc_classes.txt'
classes_path = 'model_data/kitti_classes.txt'
anchors_path = 'model_data/yolo_anchors.txt'

Go to LIne 32: Change the name of the pre-trained weight file.

  • We will use COCO trained weight file as we used above(yolo.h5). Create a copy and name it asyolo_weights.h5

    if is_tiny_version:
        model = create_tiny_model(input_shape, anchors, num_classes,
            freeze_body=2, weights_path='model_data/yolo_tiny_weights.h5')
    else:
        model = create_model(input_shape, anchors, num_classes,
            freeze_body=2, weights_path='model_data/yolo_weights.h5') # make sure you know what you freeze

Run Train

Start training by running the following in the terminal

>>python train.py

Evaluate

Use your trained weights or checkpoint weights with command line option --model model_file when using yolo_video.py Remember to modify the class path or anchor path.

TroubleShooting

Problem 1

Error message of

_, ignore_mask = K.control_flow_ops.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])

Solution

Modify model.py (line 394)

_, ignore_mask = K.control_flow_ops.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])

should be changed to

_, ignore_mask = tf.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])

git

YOLOv3 weights

wget ``

Image file:

Label file:

Object Detection annotation Convert to Yolo Darknet Format:

https://github.com/qqwweee/keras-yolo3
https://github.com/qqwweee/keras-yolo3.git
https://pjreddie.com/media/files/yolov3.weights
https://pjreddie.com/media/files/yolov3.weights
https://pjreddie.com/media/files/yolov3-tiny.weights
Download Kitti Dataset
Download Kitti Dataset Label
Click here