Modified on Eric's code and README.
-
Download Coalabeler via http://www.colabeler.com and install it
-
Open Colabeler and create a new project
-
Choose the Image Folder Classification Values: particle
-
Open the project you created, note that it may not work at once, try a few times until images show up
-
In your keyboard, type "R" to select the Rectangle tool, and start labelling. Remember to type your label name for the first time
During your labelling, please remember to click "✅" or Crtl+s to save your work. This software is not stable
-
After you finishing one image's labelling, use you direction key to go to the next image.
-
After all the labelling, select Export and choose XML export method. (You can first try to export once you start labelling, this is also not stable on MacOS so you may try many times, or try restarting your computer)
Conda
# Tensorflow GPU
conda env create -f conda-gpu.yml
conda activate yolov3-tf2-gpu
File: Cutting.ipynb
Usage: To cut images into smaller pieces. You can find the detailed steps in the file.
Note that data augmentation techniques (rotation, flip, brightness, random noise) are used so your total images should be approximately
. Also note that some cut section may does not include any images, so they are not generated.
Name | Description |
---|---|
benchmark/ | Temporary directory for mAP calculation. |
benchmark.py | Calculate mAP for files in benchmark/ . |
checkpoints/ | Store the training models in each epoch. |
conda-cpu.yml | Conda environment file for cpu. |
conda-gpu.yml | Conda environment file for gpu. |
convert.py | Convert YoloV3 weights into tensor-flow model. |
data/ | Temporary dictionary for data storage. |
data_convert.py | Convert labeled figure into tfrecords. |
detect_list.py | Detect a list of image in tfrecords. |
detect.py | Detect a single image. |
logs/ | Store tenser-board files in training. |
model_mAP.py | Calculate mAP for models in each epoch. |
samples/ | Store image samples. |
train.py | Program for traning the model. |
yolov3_tf2/ | Files for YoloV3 model. |
detect1.py | My modified version of detect.py |
Make a temperoray directory first under /training/yolov3_tf2/tmp/
.
Under training
folder
wget https://pjreddie.com/media/files/yolov3.weights -O data/yolov3.weights
python convert.py --weights ./data/yolov3.weights --output ./checkpoints/yolov3.tf
In our dataset, the labeled dataset is stored in label.txt
, in which the labels are arranged as follows:
Path_1 Xmin_1,Ymin_1,Xmax_1,Ymax_1 ... Xmin_n1,Ymin_n1,Xmax_n1,Ymax_n1
Path_2 Xmin_1,Ymin_1,Xmax_1,Ymax_1 ... Xmin_n2,Ymin_n2,Xmax_n2,Ymax_n2
...
Path_m Xmin_1,Ymin_1,Xmax_1,Ymax_1 ... Xmin_nm,Ymin_nm,Xmax_nm,Ymax_nm
You may use data_convert.py
to convert the images into tfrecords for training.
Example:
Under training
folder
python data_convert.py --dataset ./label.txt
The train.py
takes some command line arguments and trains the model. Please see Command Line Args Reference for more information.
Example:
Under training
folder
python train.py --classes ./data/particle.names --dataset ./data/particle_train.tfrecord --val_dataset ./data/particle_val.tfrecord --epochs 25 --learning_rate 1e-4 --num_classes 1 --transfer darknet --weights ./checkpoints/yolov3.tf --weights_num_classes 80
The model for each epoch can be found in checkpoints/
. You can use model_mAP.py
to obtain the mAP of each model in both training set and validation set. (Make sure you use the same validation dataset as training.)
convert.py:
--output: path to output
(default: './checkpoints/yolov3.tf')
--[no]tiny: yolov3 or yolov3-tiny
(default: 'false')
--weights: path to weights file
(default: './data/yolov3.weights')
--num_classes: number of classes in the model
(default: '80')
(an integer)
detect.py:
--classes: path to classes file
(default: './data/particle.names')
--image: path to input image
(default: './data/girl.png')
--num_classes: number of classes in the model
(default: '80')
(an integer)
--output: path to output image
(default: './output.jpg')
--size: resize images to
(default: '416')
(an integer)
--tfrecord: tfrecord instead of image
--weights: path to weights file
(default: './checkpoints/yolov3.tf')
train.py:
--batch_size: batch size
(default: '8')
(an integer)
--classes: path to classes file
(default: './data/particle.names')
--dataset: path to dataset
(default: '')
--epochs: number of epochs
(default: '2')
(an integer)
--learning_rate: learning rate
(default: '0.0001')
(a number)
--mode: <fit|eager_fit|eager_tf>: fit: model.fit, eager_fit:
model.fit(run_eagerly=True), eager_tf: custom GradientTape
(default: 'fit')
--num_classes: number of classes in the model
(default: '1')
(an integer)
--size: image size
(default: '416')
(an integer)
--transfer: <none|darknet|no_output|frozen|fine_tune>: none: Training from
scratch, darknet: Transfer darknet, no_output: Transfer all but output,
frozen: Transfer and freeze all, fine_tune: Transfer all and freeze darknet
only
(default: 'none')
--val_dataset: path to validation dataset
(default: '')
--weights: path to weights file
(default: './checkpoints/yolov3.tf')
--weights_num_classes: specify num class for `weights` file if different,
useful in transfer learning with different number of classes
(an integer)
data_convert.py:
--dataset: path to dataset label file
(default: '')
--output: path to output folder
(default: 'data/')
--subset: get a subset of training set (0 ~ 1)
(default: '1.0')
(a number)
--val_split: validation split
(default: '0.2')
(a number)
detect_list.py:
--batch_size: number of batch size for detection
(default: '12')
(an integer)
--classes: path to classes file
(default: './data/particle.names')
--num_classes: number of classes in the model
(default: '1')
(an integer)
--size: resize images to
(default: '416')
(an integer)
--tfrecord: path to tfrecord
--weights: path to weights file
(default: './checkpoints/yolov3.tf')
model_mAP.py:
--batch_size: batch size
(default: '8')
(an integer)
--classes: path to classes file
(default: './data/particle.names')
--epochs: ending epochs to calcuate mAP
(default: '1')
(an integer)
--epochs_start: starting epochs to calcuate mAP
(default: '1')
(an integer)
--num_classes: number of classes in the model
(default: '1')
(an integer)
--size: image size
(default: '416')
(an integer)
--train_dataset: path to dataset
(default: './data/particle_train.tfrecord')
--val_dataset: path to validation dataset
(default: './data/particle_val.tfrecord')
--weights_path: path to weights files
(default: './checkpoints/')
For simplicity, I use the 25th benchmark as the weights and modified it in the detect1.py
file.
Example:
Under training
folder
python detect1.py --cut_size 100 --image_type tif --image_directory /home/yl768/UVM_H/images/46k_105C/2/ --output_type boxes --output /home/yl768/UVM_H/output/46K/
File: Track.ipynb
Usage: To find the trajectory of the particles using trackpy
. A tutorial of trackpy
can be found at http://soft-matter.github.io/trackpy/dev/tutorial/walkthrough.html.
You should be able to export the xls file like this.
- https://github.com/zzh8829/yolov3-tf2
- yolov3 implementation in tf2
- https://github.com/Cartucho/mAP
- mAP calculation
This work was sponsored and supported by Prof. Kai Zhang. Eric Zhonghang Qu has given me tremendous support in my initial set-up of the environment. Kamlesh Bornani, PhD kindly provided the TEM images and shared many great insights with me.