Code Monkey home page Code Monkey logo

flower_detection's Introduction

Flower Classification after Detection

Aaron Swartz

Python Package, Tool Source and Data Source

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import keras
import os
import torchvision.transforms as T
import torch,torchvision
from ann_visualizer.visualize import ann_viz

lable tool

git clone https://github.com/tzutalin/labelImg.git

kaggle dataset

kaggle datasets download -d alxmamaev/flowers-recognition

YOLOv3 architecture

git clone https://github.com/pjreddie/darknet

Resnet18 architecture

cd darknet
git clone https://github.com/yyf710670079/flower_detection_minorPJ.git

The first step: Preprocess the data

  1. Use Python to rename all the picture in order to make labeling convenient. (number_train_imagedir.jpg, number_test_imagedir.jpg)

cd flower_detection_minorPJ

# "os.getcwd" change to your path of dataset
vi change_picname.py 


python3 change_picname.py
  1. Data augmentation: Flip and Random Crop by using python PIL package.

cd flower_detection_minorPJ


# delete several "#" and change the path to your own
vi data_augmentation.py  


python3 data_augmentation.py

The second step: Label the image

  1. Use LabelImg to label the dataset and generate a file including cordinates and classes.

git clone https://github.com/tzutalin/labelImg.git
cd labelImg
python3 labelImg.py
  1. Pack the whole label text and match each picture.

cd flower_detection_minorPJ

# change the image file's path to your own
vi create_flower_pathFile.py 


python3 create_flower_pathFile.py
cd ..
mv cfg/voc.data flower_detection_minorPJ/flower_voc.data
vi flower_detection_minorPJ/flower_voc.data

classes= 4  
train  = flower_detection_minorPJ/flower_train.txt 
# path of training set labels
valid  = flower_detection_minorPJ/flower_train.txt 
# path of valid set labels which you should create by your own like flower_train.txt
names = flower_detection_minorPJ/flower_voc.names 
backup = flower_detection_minorPJ/backup 
#create by your own

mv data/voc.names flower_detection_minorPJ/flower_voc.names 
vi flower_detection_minorPJ/flower_voc.names 

'''
daisy
tulip
rose
sunflower
'''

mv cfg/yolov3-voc.cfg flower_detection_minorPJ/yolov3-voc.cfg
vi flower_detection_minorPJ/yolov3-voc.cfg

[convolutional]
size=1
stride=1
pad=1
filters=27         
#filters = 3*(classes + 5)  3 places need to be altered
activation=linear
[yolo]
mask = 0,1,2

The third step: Train the Yolo model

While predicting:

input : 3 x height x width image

return: bounding boxes' cordinates and corresponding class information

cd darknet
# download weights
wget https://pjreddie.com/media/files/darknet53.conv.74

# train
./darknet detector train flower_detection_minorPJ/flower_voc.data flower_detection_minorPJ/yolov3-voc.cfg darknet53.conv.74 

# test
./darknet detector test flower_detection_minorPJ/flower_voc.data flower_detection_minorPJ/yolov3-voc.cfg flower_detection_minorPJ/backup/yolov3-voc_final.weights flower_detection_minorPJ/test_data/test_img.jpg

# limited by github, I cannot upload my weights.
# You can contact me if you want
# [email protected]

The fourth step: Crop the images into several segments

To crop images by the bounding boxes and temporarily save the class information.

cd flower_detection_minorPJ
vi cropBox.py 

The fifth step: Train the Residual Neural Network

While predicting:

input: an particular enlarged image

return: the class information

# train
cd flower_detection_minorPJ
python3 model_2.py train resnet18_100.pkl

# test
python3 model_2.py test resnet18_best3.pkl flower_test

The last step: Outcome and visualization

Resnet-18 loss function

Aaron Swartz

YOLOv3 loss function

Aaron Swartz

Test accuracy of Resnet

Aaron Swartz

Train accuracy of Resnet

Aaron Swartz

YOLOv3 test RECALL

Aaron Swartz

TEST IMAGES

Aaron Swartz

flower_detection's People

Contributors

yfyang16 avatar

Stargazers

 avatar  avatar  avatar 郑煜伟 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.