Coder Social home page Coder Social logo

aim-dection-issue / yolov4_tensorflow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from randomchuan/yolov4_tensorflow

0.0 1.0 0.0 7.3 MB

implement yolov4 with pure tensorflow and you can training net on your own dataset. YOLOv4的纯tensorflow实现,可训练自己的模型.

Python 100.00%

yolov4_tensorflow's Introduction

YOLOv4_tensorflow | 中文说明

  • Implement yolov4 with pure tensorflow
  • implemented the part of data augment strategies
  • continuous update the code

introductions

  • run the following command.
python val.py
  • if have no error, it's ok

convert yolov4.weights to fit our code

  • refer to this weights convert file, I'm already converted yolov4.weights to this project.
  • you can download yolov4.weights from baidu cloud Extraction code: wm1j
  • put yolov4.weights into the "yolo_weights" folder, and run the command.
python convert_weight.py
python test_yolo_weights.py
  • the ckpt weights file wound exits in the 'yolo_weights' folder(exists in the baidu cloud)
  • and you'll see some images like this, it seems perfect

image * image * image *

  • the weights_name.txt contains all model layer's name of the network

train on VOC2007 and VOC2012

  • open config.py and modify the voc_root_dir to the root of your VOC dataset, modify the voc_dir_ls to the name of VOC dataset witch you want to train
  • just like this
path_to_voc_root_dir
        voc_dir_ls[0] (VOC_2007)
        |       |Annotations
        |       |JPEGImages
        |       |...
        voc_dir_ls[1] (VOC_2012)
        |        |Annotations
        |        |JPEGImages
        |        |...
        others_folder_name
  • run the command
python train_voc.py
  • put test images into voc_test_pic folder, and run the following command after the model training finished.
python val_voc.py
  • it's the result of our code training(input_size:416*416, batch_size:2, lr:2e-4, optimizer:momentum) for a day(364999 steps), not bad

image * image *

  • all configuration parameters are in the config.py, you can modify them according to your actual situation
  • it's the image of loss value, and seems that the lr is too lower(2e-4), we should set it larger.
python show_loss.py 20 300

image *

train with own dataset

  • The jpg image and the corresponding json file which marked with labelme are stored in the folder ./data/JPEGImages, just like what I do in the ./data/JPEGImages folder
  • and then, go to the folder ./data, execute the following python command, it automatically generates label files and train.txt
python generate_labels.py
  • excute the python command, to get anchor box
python k_means.py
  • open config.py, write the anchor box to line 6, just like this
anchors = 12,19, 19,27, 18,37, 21,38, 23,38, 26,39, 31,38, 39,44, 67,96
  • and, now, modify the content in data/train.names to the category name that you need to train, and change the class_num in config.py to your own category number.
  • all configuration parameters are in the config.py, you can modify them according to your actual situation
  • ok, that's all, execute the command
python train.py
  • puts images into test_pic folder, and run the following command after the model training finished.
python val.py
  • this image is the result of training 5000 steps (25 minutes) with 123 pictures, it looks not bad.

image

convert ckpt model to pb model

  • open ckpt2pb.py , and modify 'ckpt_file_dir', 'class_num', 'anchors'. run.
python ckpt2pb.py
  • you will see a pb model named 'model.pb' in 'ckpt_file_dir'
  • if you want to use pb model, you will learn more from 'val_pb.py'
  • run python file
python val_pb.py
  • you will see the detection results with pb model
  • you can download pb model from baidu cloud Extraction code: wm1j

some tips with config.py and train the model

  1. the parameters of width and height in config.py should be 608, but i have not a powerful GPU, that is why i set them as 416
  2. actually, you can replace mish activation with leaky_relu to save GPU memory, and then you can set batch_size from 2 to 4
  3. learning rate do not set too large
  4. when the loss value is Nan, please lower your learning rate.

my device

GPU : 1660ti (ASUS) 6G
CPU : i5 9400f
mem : 16GB
os : ubuntu 18.04
cuda: 10.2
cudnn : 7
python : 3.6.9
tensorflow-gpu:1.14.0
numpy : 1.18.1
opencv-python : 4.1.2.30

yolov4_tensorflow's People

Contributors

rrddcc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.