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
git clone https://github.com/tzutalin/labelImg.git
kaggle datasets download -d alxmamaev/flowers-recognition
git clone https://github.com/pjreddie/darknet
cd darknet
git clone https://github.com/yyf710670079/flower_detection_minorPJ.git
- 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
- 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
- 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
- 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
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]
To crop images by the bounding boxes and temporarily save the class information.
cd flower_detection_minorPJ
vi cropBox.py
# train
cd flower_detection_minorPJ
python3 model_2.py train resnet18_100.pkl
# test
python3 model_2.py test resnet18_best3.pkl flower_test