├── plant_counting.png
├── requirements.txt
├── snapshots
├── mtc
│ └── tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500
│ │ ├── learning_curves.png
│ │ ├── model_best.pth.tar
│ │ └── tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500.txt
├── wec
│ └── tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500
│ │ ├── learning_curves.png
│ │ ├── model_best.pth.tar
│ │ └── tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500.txt
└── shc
│ ├── tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500
│ ├── learning_curves.png
│ ├── model_best.pth.tar
│ └── model_ckpt.pth.tar
│ └── tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500
│ ├── learning_curves.png
│ ├── model_best.pth.tar
│ └── tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500.txt
├── config
├── hl_mtc_train.sh
├── hl_wec_train.sh
├── hl_shc_train.sh
├── hl_mtc_eval.sh
├── hl_wec_eval.sh
└── hl_shc_eval.sh
├── gen_trainval_list.py
├── data
├── sorghum_head_counting_dataset
│ ├── dataset2_train.txt
│ ├── dataset2_test.txt
│ ├── dataset1_test.txt
│ └── dataset1_train.txt
├── wheat_ears_counting_dataset
│ ├── val.txt
│ └── train.txt
└── maize_counting_dataset
│ ├── test.txt
│ └── train.txt
├── utils.py
├── README.md
├── hlnet.py
├── hldataset.py
├── hltrainval.py
└── LICENSE
/plant_counting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/plant_counting.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | torch
2 | torchvision
3 | opencv-python
4 | numpy
5 | PIL
6 | matplotlib
7 | scipy
8 | skimage
9 | sklearn
10 | math
11 | json
12 | pandas
13 | h5py
14 | xml
--------------------------------------------------------------------------------
/snapshots/mtc/tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500/learning_curves.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/mtc/tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500/learning_curves.png
--------------------------------------------------------------------------------
/snapshots/mtc/tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500/model_best.pth.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/mtc/tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500/model_best.pth.tar
--------------------------------------------------------------------------------
/snapshots/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500/learning_curves.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500/learning_curves.png
--------------------------------------------------------------------------------
/snapshots/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500/model_best.pth.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500/model_best.pth.tar
--------------------------------------------------------------------------------
/snapshots/shc/tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/learning_curves.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/shc/tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/learning_curves.png
--------------------------------------------------------------------------------
/snapshots/shc/tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/model_best.pth.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/shc/tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/model_best.pth.tar
--------------------------------------------------------------------------------
/snapshots/shc/tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/model_ckpt.pth.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/shc/tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/model_ckpt.pth.tar
--------------------------------------------------------------------------------
/snapshots/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/learning_curves.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/learning_curves.png
--------------------------------------------------------------------------------
/snapshots/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/model_best.pth.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poppinace/tasselnetv2plus/HEAD/snapshots/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/model_best.pth.tar
--------------------------------------------------------------------------------
/config/hl_mtc_train.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES=0 python hltrainval.py \
2 | --data-dir ./data/maize_counting_dataset \
3 | --dataset mtc \
4 | --model tasselnetv2plus \
5 | --exp tasselnetv2plus \
6 | --data-list ./data/maize_counting_dataset/train.txt \
7 | --data-val-list ./data/maize_counting_dataset/test.txt \
8 | --restore-from model_best.pth.tar \
9 | --image-mean 0.3859 0.4905 0.2895 \
10 | --image-std 0.1718 0.1712 0.1518 \
11 | --input-size 64 \
12 | --output-stride 8 \
13 | --resize-ratio 0.125 \
14 | --optimizer sgd \
15 | --milestones 200 400 \
16 | --batch-size 9 \
17 | --crop-size 256 256 \
18 | --learning-rate 1e-2 \
19 | --num-epochs 500 \
20 | --num-workers 0 \
21 | --print-every 10 \
22 | --random-seed 2020 \
23 | --val-every 10
--------------------------------------------------------------------------------
/config/hl_wec_train.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES=0 python hltrainval.py \
2 | --data-dir ./data/wheat_ears_counting_dataset \
3 | --dataset wec \
4 | --model tasselnetv2plus \
5 | --exp tasselnetv2plus \
6 | --data-list ./data/wheat_ears_counting_dataset/train.txt \
7 | --data-val-list ./data/wheat_ears_counting_dataset/val.txt \
8 | --restore-from model_best.pth.tar \
9 | --image-mean 0.4051 0.4392 0.2344 \
10 | --image-std 0.2569 0.2620 0.2287 \
11 | --input-size 64 \
12 | --output-stride 8 \
13 | --resize-ratio 0.167 \
14 | --optimizer sgd \
15 | --milestones 200 400 \
16 | --batch-size 8 \
17 | --crop-size 512 512 \
18 | --learning-rate 1e-2 \
19 | --num-epochs 500 \
20 | --num-workers 0 \
21 | --print-every 10 \
22 | --random-seed 2020 \
23 | --val-every 10
--------------------------------------------------------------------------------
/config/hl_shc_train.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES=0 python hltrainval.py \
2 | --data-dir ./data/sorghum_head_counting_dataset \
3 | --dataset shc \
4 | --model tasselnetv2plus \
5 | --exp tasselnetv2plus \
6 | --data-list ./data/sorghum_head_counting_dataset/dataset1_train.txt \
7 | --data-val-list ./data/sorghum_head_counting_dataset/dataset1_test.txt \
8 | --restore-from model_best.pth.tar \
9 | --image-mean 0.3714 0.3609 0.2386 \
10 | --image-std 0.2705 0.2567 0.2161 \
11 | --input-size 64 \
12 | --output-stride 8 \
13 | --resize-ratio 1 \
14 | --optimizer sgd \
15 | --milestones 200 400 \
16 | --batch-size 5 \
17 | --crop-size 256 1024 \
18 | --learning-rate 1e-2 \
19 | --num-epochs 500 \
20 | --num-workers 0 \
21 | --print-every 5 \
22 | --random-seed 2020 \
23 | --val-every 10
--------------------------------------------------------------------------------
/config/hl_mtc_eval.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES=0 python hltrainval.py \
2 | --data-dir ./data/maize_counting_dataset \
3 | --dataset mtc \
4 | --model tasselnetv2plus \
5 | --exp tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500 \
6 | --data-list ./data/maize_counting_dataset/train.txt \
7 | --data-val-list ./data/maize_counting_dataset/test.txt \
8 | --restore-from model_best.pth.tar \
9 | --image-mean 0.3859 0.4905 0.2895 \
10 | --image-std 0.1718 0.1712 0.1518 \
11 | --input-size 64 \
12 | --output-stride 8 \
13 | --resize-ratio 0.125 \
14 | --optimizer sgd \
15 | --milestones 200 400 \
16 | --batch-size 9 \
17 | --crop-size 256 256 \
18 | --learning-rate 1e-2 \
19 | --num-epochs 500 \
20 | --num-workers 0 \
21 | --print-every 10 \
22 | --random-seed 2020 \
23 | --val-every 10 \
24 | --evaluate-only \
25 | --save-output
--------------------------------------------------------------------------------
/config/hl_wec_eval.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES=0 python hltrainval.py \
2 | --data-dir ./data/wheat_ears_counting_dataset \
3 | --dataset wec \
4 | --model tasselnetv2plus \
5 | --exp tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500 \
6 | --data-list ./data/wheat_ears_counting_dataset/train.txt \
7 | --data-val-list ./data/wheat_ears_counting_dataset/val.txt \
8 | --restore-from model_best.pth.tar \
9 | --image-mean 0.4051 0.4392 0.2344 \
10 | --image-std 0.2569 0.2620 0.2287 \
11 | --input-size 64 \
12 | --output-stride 8 \
13 | --resize-ratio 0.167 \
14 | --optimizer sgd \
15 | --milestones 200 400 \
16 | --batch-size 8 \
17 | --crop-size 512 512 \
18 | --learning-rate 1e-2 \
19 | --num-epochs 500 \
20 | --num-workers 0 \
21 | --print-every 10 \
22 | --random-seed 2020 \
23 | --val-every 10 \
24 | --evaluate-only \
25 | --save-output
--------------------------------------------------------------------------------
/config/hl_shc_eval.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES=0 python hltrainval.py \
2 | --data-dir ./data/sorghum_head_counting_dataset \
3 | --dataset shc \
4 | --model tasselnetv2plus \
5 | --exp tasselnetv2plus_dataset1_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500 \
6 | --data-list ./data/sorghum_head_counting_dataset/dataset1_train.txt \
7 | --data-val-list ./data/sorghum_head_counting_dataset/dataset1_test.txt \
8 | --restore-from model_best.pth.tar \
9 | --image-mean 0.3714 0.3609 0.2386 \
10 | --image-std 0.2705 0.2567 0.2161 \
11 | --input-size 64 \
12 | --output-stride 8 \
13 | --resize-ratio 1 \
14 | --optimizer sgd \
15 | --milestones 200 400 \
16 | --batch-size 5 \
17 | --crop-size 256 1024 \
18 | --learning-rate 1e-2 \
19 | --num-epochs 500 \
20 | --num-workers 0 \
21 | --print-every 5 \
22 | --random-seed 2020 \
23 | --val-every 10 \
24 | --evaluate-only \
25 | --save-output
--------------------------------------------------------------------------------
/gen_trainval_list.py:
--------------------------------------------------------------------------------
1 | import os
2 | import glob
3 | import random
4 |
5 | root = './data/wheat_ears_counting_dataset'
6 | image_folder = 'images'
7 | label_folder = 'labels'
8 | train = 'train'
9 | val = 'val'
10 |
11 | train_path = os.path.join(root, train)
12 | with open('train.txt', 'w') as f:
13 | for image_path in glob.glob(os.path.join(train_path, image_folder, '*.JPG')):
14 | im_path = image_path.replace(root, '')
15 | gt_path = im_path.replace(image_folder, label_folder).replace('.JPG', '.xml')
16 | f.write(im_path+'\t'+gt_path+'\n')
17 |
18 | val_path = os.path.join(root, val)
19 | with open('val.txt', 'w') as f:
20 | for image_path in glob.glob(os.path.join(val_path, image_folder, '*.JPG')):
21 | im_path = image_path.replace(root, '')
22 | gt_path = im_path.replace(image_folder, label_folder).replace('.JPG', '.xml')
23 | f.write(im_path+'\t'+gt_path+'\n')
--------------------------------------------------------------------------------
/data/sorghum_head_counting_dataset/dataset2_train.txt:
--------------------------------------------------------------------------------
1 | /original/dataset2/C1-R20-G18-DSC01050.tif /labeled/dataset2/C1-R20-G18-DSC01050-hand.png
2 | /original/dataset2/C16-R9-G127-DSC00827.tif /labeled/dataset2/C16-R9-G127-DSC00827-hand.png
3 | /original/dataset2/C5-R13-G139-DSC00885.tif /labeled/dataset2/C5-R13-G139-DSC00885-hand.png
4 | /original/dataset2/C5-R25-G148-DSC01295.tif /labeled/dataset2/C5-R25-G148-DSC01295-hand.png
5 | /original/dataset2/C18-R21-G519-DSC01086.tif /labeled/dataset2/C18-R21-G519-DSC01086-hand.png
6 | /original/dataset2/C4-R3-G98-DSC00677.tif /labeled/dataset2/C4-R3-G98-DSC00677-hand.png
7 | /original/dataset2/C21-R10-G471-DSC00815.tif /labeled/dataset2/C21-R10-G471-DSC00815-hand.png
8 | /original/dataset2/C15-R39-G98-DSC01883.tif /labeled/dataset2/C15-R39-G98-DSC01883-hand.png
9 | /original/dataset2/C18-R4-G184-DSC00648.tif /labeled/dataset2/C18-R4-G184-DSC00648-hand.png
10 | /original/dataset2/C11-R13-G325-DSC00897.tif /labeled/dataset2/C11-R13-G325-DSC00897-hand.png
11 | /original/dataset2/C3-R20-G34-DSC01054.tif /labeled/dataset2/C3-R20-G34-DSC01054-hand.png
12 | /original/dataset2/C13-R28-G47-DSC01454.tif /labeled/dataset2/C13-R28-G47-DSC01454-hand.png
13 | /original/dataset2/C24-R27-G669-DSC01359.tif /labeled/dataset2/C24-R27-G669-DSC01359-hand.png
14 | /original/dataset2/C2-R1-G34-DSC00532.tif /labeled/dataset2/C2-R1-G34-DSC00532-hand.png
15 | /original/dataset2/C34-R34-G300-DSC01818.tif /labeled/dataset2/C34-R34-G300-DSC01818-hand.png
16 | /original/dataset2/C20-R21-G139-DSC01090.tif /labeled/dataset2/C20-R21-G139-DSC01090-hand.png
17 | /original/dataset2/C30-R10-G569-DSC00795.tif /labeled/dataset2/C30-R10-G569-DSC00795-hand.png
18 | /original/dataset2/C4-R39-G127-DSC01906.tif /labeled/dataset2/C4-R39-G127-DSC01906-hand.png
19 | /original/dataset2/C35-R17-G899-DSC00960.tif /labeled/dataset2/C35-R17-G899-DSC00960-hand.png
20 | /original/dataset2/C36-R20-G899-DSC01123.tif /labeled/dataset2/C36-R20-G899-DSC01123-hand.png
21 |
--------------------------------------------------------------------------------
/data/sorghum_head_counting_dataset/dataset2_test.txt:
--------------------------------------------------------------------------------
1 | /original/dataset2/C13-R14-G384-DSC00901.tif /labeled/dataset2/C13-R14-G384-DSC00901-hand.png
2 | /original/dataset2/C11-R16-G328-DSC01010.tif /labeled/dataset2/C11-R16-G328-DSC01010-hand.png
3 | /original/dataset2/C16-R6-G148-DSC00733.tif /labeled/dataset2/C16-R6-G148-DSC00733-hand.png
4 | /original/dataset2/C20-R20-G569-DSC01090.tif /labeled/dataset2/C20-R20-G569-DSC01090-hand.png
5 | /original/dataset2/C25-R7-G519-DSC00752.tif /labeled/dataset2/C25-R7-G519-DSC00752-hand.png
6 | /original/dataset2/C28-R22-G384-DSC01147.tif /labeled/dataset2/C28-R22-G384-DSC01147-hand.png
7 | /original/dataset2/C8-R17-G240-DSC01017.tif /labeled/dataset2/C8-R17-G240-DSC01017-hand.png
8 | /original/dataset2/C23-R39-G287-DSC01786.tif /labeled/dataset2/C23-R39-G287-DSC01786-hand.png
9 | /original/dataset2/C24-R10-G579-DSC00808.tif /labeled/dataset2/C24-R10-G579-DSC00808-hand.png
10 | /original/dataset2/C20-R38-G579-DSC01780.tif /labeled/dataset2/C20-R38-G579-DSC01780-hand.png
11 | /original/dataset2/C2-R17-G47-DSC01029.tif /labeled/dataset2/C2-R17-G47-DSC01029-hand.png
12 | /original/dataset2/C10-R1-G287-DSC00549.tif /labeled/dataset2/C10-R1-G287-DSC00549-hand.png
13 | /original/dataset2/C6-R28-G184-DSC01469.tif /labeled/dataset2/C6-R28-G184-DSC01469-hand.png
14 | /original/dataset2/C27-R21-G325-DSC01104.tif /labeled/dataset2/C27-R21-G325-DSC01104-hand.png
15 | /original/dataset2/C30-R19-G669-DSC01111.tif /labeled/dataset2/C30-R19-G669-DSC01111-hand.png
16 | /original/dataset2/C25-R22-G240-DSC01154.tif /labeled/dataset2/C25-R22-G240-DSC01154-hand.png
17 | /original/dataset2/C2-R4-G18-DSC00681.tif /labeled/dataset2/C2-R4-G18-DSC00681-hand.png
18 | /original/dataset2/C10-R18-G300-DSC01013.tif /labeled/dataset2/C10-R18-G300-DSC01013-hand.png
19 | /original/dataset2/C33-R39-G328-DSC01845.tif /labeled/dataset2/C33-R39-G328-DSC01845-hand.png
20 | /original/dataset2/C16-R22-G471-DSC01173.tif /labeled/dataset2/C16-R22-G471-DSC01173-hand.png
21 |
--------------------------------------------------------------------------------
/data/sorghum_head_counting_dataset/dataset1_test.txt:
--------------------------------------------------------------------------------
1 | /original/dataset1/DSC01298-crop.jpg /labeled/dataset1/DSC01298-crop-hand.png
2 | /original/dataset1/DSC02083-crop.jpg /labeled/dataset1/DSC02083-crop-hand.png
3 | /original/dataset1/DSC01562-crop.jpg /labeled/dataset1/DSC01562-crop-hand.png
4 | /original/dataset1/DSC02151-crop.jpg /labeled/dataset1/DSC02151-crop-hand.png
5 | /original/dataset1/DSC00732-crop.jpg /labeled/dataset1/DSC00732-crop-hand.png
6 | /original/dataset1/DSC02262-crop.jpg /labeled/dataset1/DSC02262-crop-hand.png
7 | /original/dataset1/DSC00527-crop.jpg /labeled/dataset1/DSC00527-crop-hand.png
8 | /original/dataset1/DSC01338-crop.jpg /labeled/dataset1/DSC01338-crop-hand.png
9 | /original/dataset1/DSC01537-crop.jpg /labeled/dataset1/DSC01537-crop-hand.png
10 | /original/dataset1/DSC00706-crop.jpg /labeled/dataset1/DSC00706-crop-hand.png
11 | /original/dataset1/DSC01777-crop.jpg /labeled/dataset1/DSC01777-crop-hand.png
12 | /original/dataset1/DSC00971-crop.jpg /labeled/dataset1/DSC00971-crop-hand.png
13 | /original/dataset1/DSC00655-crop.jpg /labeled/dataset1/DSC00655-crop-hand.png
14 | /original/dataset1/DSC02085-crop.jpg /labeled/dataset1/DSC02085-crop-hand.png
15 | /original/dataset1/DSC02286-crop.jpg /labeled/dataset1/DSC02286-crop-hand.png
16 | /original/dataset1/DSC02263-crop.jpg /labeled/dataset1/DSC02263-crop-hand.png
17 | /original/dataset1/DSC01807-crop.jpg /labeled/dataset1/DSC01807-crop-hand.png
18 | /original/dataset1/DSC01528-crop.jpg /labeled/dataset1/DSC01528-crop-hand.png
19 | /original/dataset1/DSC00889-crop.jpg /labeled/dataset1/DSC00889-crop-hand.png
20 | /original/dataset1/DSC02011-crop.jpg /labeled/dataset1/DSC02011-crop-hand.png
21 | /original/dataset1/DSC02413-crop.jpg /labeled/dataset1/DSC02413-crop-hand.png
22 | /original/dataset1/DSC02425-crop.jpg /labeled/dataset1/DSC02425-crop-hand.png
23 | /original/dataset1/DSC00895-crop.jpg /labeled/dataset1/DSC00895-crop-hand.png
24 | /original/dataset1/DSC02401-crop.jpg /labeled/dataset1/DSC02401-crop-hand.png
25 | /original/dataset1/DSC02562-crop.jpg /labeled/dataset1/DSC02562-crop-hand.png
26 | /original/dataset1/DSC02258-crop.jpg /labeled/dataset1/DSC02258-crop-hand.png
27 |
--------------------------------------------------------------------------------
/data/sorghum_head_counting_dataset/dataset1_train.txt:
--------------------------------------------------------------------------------
1 | /original/dataset1/DSC01890-crop.jpg /labeled/dataset1/DSC01890-crop-hand.png
2 | /original/dataset1/DSC00952-crop.jpg /labeled/dataset1/DSC00952-crop-hand.png
3 | /original/dataset1/DSC00554-crop.jpg /labeled/dataset1/DSC00554-crop-hand.png
4 | /original/dataset1/DSC02339-crop.jpg /labeled/dataset1/DSC02339-crop-hand.png
5 | /original/dataset1/DSC00613-crop.jpg /labeled/dataset1/DSC00613-crop-hand.png
6 | /original/dataset1/DSC00941-crop.jpg /labeled/dataset1/DSC00941-crop-hand.png
7 | /original/dataset1/DSC01983-crop.jpg /labeled/dataset1/DSC01983-crop-hand.png
8 | /original/dataset1/DSC02291-crop.jpg /labeled/dataset1/DSC02291-crop-hand.png
9 | /original/dataset1/DSC01154-crop.jpg /labeled/dataset1/DSC01154-crop-hand.png
10 | /original/dataset1/DSC01024-crop.jpg /labeled/dataset1/DSC01024-crop-hand.png
11 | /original/dataset1/DSC00748-crop.jpg /labeled/dataset1/DSC00748-crop-hand.png
12 | /original/dataset1/DSC01402-crop.jpg /labeled/dataset1/DSC01402-crop-hand.png
13 | /original/dataset1/DSC00781-crop.jpg /labeled/dataset1/DSC00781-crop-hand.png
14 | /original/dataset1/DSC00532-crop.jpg /labeled/dataset1/DSC00532-crop-hand.png
15 | /original/dataset1/DSC01826-crop.jpg /labeled/dataset1/DSC01826-crop-hand.png
16 | /original/dataset1/DSC02241-crop.jpg /labeled/dataset1/DSC02241-crop-hand.png
17 | /original/dataset1/DSC01748-crop.jpg /labeled/dataset1/DSC01748-crop-hand.png
18 | /original/dataset1/DSC02441-crop.jpg /labeled/dataset1/DSC02441-crop-hand.png
19 | /original/dataset1/DSC01367-crop.jpg /labeled/dataset1/DSC01367-crop-hand.png
20 | /original/dataset1/DSC02120-crop.jpg /labeled/dataset1/DSC02120-crop-hand.png
21 | /original/dataset1/DSC02084-crop.jpg /labeled/dataset1/DSC02084-crop-hand.png
22 | /original/dataset1/DSC02487-crop.jpg /labeled/dataset1/DSC02487-crop-hand.png
23 | /original/dataset1/DSC01023-crop.jpg /labeled/dataset1/DSC01023-crop-hand.png
24 | /original/dataset1/DSC01288-crop.jpg /labeled/dataset1/DSC01288-crop-hand.png
25 | /original/dataset1/DSC01317-crop.jpg /labeled/dataset1/DSC01317-crop-hand.png
26 | /original/dataset1/DSC01289-crop.jpg /labeled/dataset1/DSC01289-crop-hand.png
27 |
--------------------------------------------------------------------------------
/utils.py:
--------------------------------------------------------------------------------
1 | """
2 | @author: hao
3 | """
4 |
5 | import scipy
6 | import numpy as np
7 | import math
8 | import cv2 as cv
9 | from scipy.ndimage import gaussian_filter, morphology
10 | from skimage.measure import label, regionprops
11 | from sklearn import linear_model
12 | import matplotlib.pyplot as plt
13 |
14 |
15 | def compute_mae(pd, gt):
16 | pd, gt = np.array(pd), np.array(gt)
17 | diff = pd - gt
18 | mae = np.mean(np.abs(diff))
19 | return mae
20 |
21 |
22 | def compute_mse(pd, gt):
23 | pd, gt = np.array(pd), np.array(gt)
24 | diff = pd - gt
25 | mse = np.sqrt(np.mean((diff ** 2)))
26 | return mse
27 |
28 | def compute_relerr(pd, gt):
29 | pd, gt = np.array(pd), np.array(gt)
30 | diff = pd - gt
31 | diff = diff[gt > 0]
32 | gt = gt[gt > 0]
33 | if (diff is not None) and (gt is not None):
34 | rmae = np.mean(np.abs(diff) / gt) * 100
35 | rmse = np.sqrt(np.mean(diff**2 / gt**2)) * 100
36 | else:
37 | rmae = 0
38 | rmse = 0
39 | return rmae, rmse
40 |
41 |
42 | def rsquared(pd, gt):
43 | """ Return R^2 where x and y are array-like."""
44 | pd, gt = np.array(pd), np.array(gt)
45 | slope, intercept, r_value, p_value, std_err = scipy.stats.linregress(pd, gt)
46 | return r_value**2
47 |
48 |
49 | def dense_sample2d(x, sx, stride):
50 | (h,w) = x.shape[:2]
51 | #idx_img = np.array([i for i in range(h*w)]).reshape(h,w)
52 | idx_img = np.zeros((h,w),dtype=float)
53 |
54 | th = [i for i in range(0, h-sx+1, stride)]
55 | tw = [j for j in range(0, w-sx+1, stride)]
56 | norm_vec = np.zeros(len(th)*len(tw))
57 |
58 | for i in th:
59 | for j in tw:
60 | idx_img[i:i+sx,j:j+sx] = idx_img[i:i+sx,j:j+sx]+1
61 |
62 | # # plot redundancy map
63 | # import os
64 | # import matplotlib.pyplot as plt
65 | # cmap = plt.cm.get_cmap('hot')
66 | # idx_img = idx_img / (idx_img.max())
67 | # idx_img = cmap(idx_img) * 255.
68 | # plt.figure()
69 | # plt.imshow(idx_img.astype(np.uint8))
70 | # plt.axis('off')
71 | # plt.savefig(os.path.join('redundancy_map.pdf'), bbox_inches='tight', dpi = 300)
72 | # plt.close()
73 |
74 | idx_img = 1/idx_img
75 | idx_img = idx_img/sx/sx
76 | #line order
77 | idx = 0
78 | for i in th:
79 | for j in tw:
80 | norm_vec[idx] =idx_img[i:i+sx,j:j+sx].sum()
81 | idx+=1
82 |
83 | return norm_vec
84 |
85 |
86 | def recover_countmap(pred, image, patch_sz, stride):
87 | pred = pred.reshape(-1)
88 | imH, imW = image.shape[2:4]
89 | cntMap = np.zeros((imH, imW), dtype=float)
90 | norMap = np.zeros((imH, imW), dtype=float)
91 |
92 | H = np.arange(0, imH - patch_sz + 1, stride)
93 | W = np.arange(0, imW - patch_sz + 1, stride)
94 | cnt = 0
95 | for h in H:
96 | for w in W:
97 | pixel_cnt = pred[cnt] / patch_sz / patch_sz
98 | cntMap[h:h+patch_sz, w:w+patch_sz] += pixel_cnt
99 | norMap[h:h+patch_sz, w:w+patch_sz] += np.ones((patch_sz,patch_sz))
100 | cnt += 1
101 | return cntMap / (norMap + 1e-12)
102 |
--------------------------------------------------------------------------------
/data/wheat_ears_counting_dataset/val.txt:
--------------------------------------------------------------------------------
1 | /val/images/5172.JPG /val/labels/5172.xml
2 | /val/images/1161.JPG /val/labels/1161.xml
3 | /val/images/3192.JPG /val/labels/3192.xml
4 | /val/images/3191.JPG /val/labels/3191.xml
5 | /val/images/4171.JPG /val/labels/4171.xml
6 | /val/images/5182.JPG /val/labels/5182.xml
7 | /val/images/2201.JPG /val/labels/2201.xml
8 | /val/images/1052.JPG /val/labels/1052.xml
9 | /val/images/3201.JPG /val/labels/3201.xml
10 | /val/images/4192.JPG /val/labels/4192.xml
11 | /val/images/1122.JPG /val/labels/1122.xml
12 | /val/images/3151.JPG /val/labels/3151.xml
13 | /val/images/3101.JPG /val/labels/3101.xml
14 | /val/images/6132.JPG /val/labels/6132.xml
15 | /val/images/3162.JPG /val/labels/3162.xml
16 | /val/images/2021.JPG /val/labels/2021.xml
17 | /val/images/5142.JPG /val/labels/5142.xml
18 | /val/images/5092.JPG /val/labels/5092.xml
19 | /val/images/6012.JPG /val/labels/6012.xml
20 | /val/images/6021.JPG /val/labels/6021.xml
21 | /val/images/4122.JPG /val/labels/4122.xml
22 | /val/images/2112.JPG /val/labels/2112.xml
23 | /val/images/3202.JPG /val/labels/3202.xml
24 | /val/images/5061.JPG /val/labels/5061.xml
25 | /val/images/5141.JPG /val/labels/5141.xml
26 | /val/images/3152.JPG /val/labels/3152.xml
27 | /val/images/2072.JPG /val/labels/2072.xml
28 | /val/images/6062.JPG /val/labels/6062.xml
29 | /val/images/4191.JPG /val/labels/4191.xml
30 | /val/images/2052.JPG /val/labels/2052.xml
31 | /val/images/4082.JPG /val/labels/4082.xml
32 | /val/images/4131.JPG /val/labels/4131.xml
33 | /val/images/2051.JPG /val/labels/2051.xml
34 | /val/images/1051.JPG /val/labels/1051.xml
35 | /val/images/1162.JPG /val/labels/1162.xml
36 | /val/images/4081.JPG /val/labels/4081.xml
37 | /val/images/4021.JPG /val/labels/4021.xml
38 | /val/images/4132.JPG /val/labels/4132.xml
39 | /val/images/2071.JPG /val/labels/2071.xml
40 | /val/images/1061.JPG /val/labels/1061.xml
41 | /val/images/1011.JPG /val/labels/1011.xml
42 | /val/images/1062.JPG /val/labels/1062.xml
43 | /val/images/6011.JPG /val/labels/6011.xml
44 | /val/images/5122.JPG /val/labels/5122.xml
45 | /val/images/3161.JPG /val/labels/3161.xml
46 | /val/images/6131.JPG /val/labels/6131.xml
47 | /val/images/5181.JPG /val/labels/5181.xml
48 | /val/images/3102.JPG /val/labels/3102.xml
49 | /val/images/2111.JPG /val/labels/2111.xml
50 | /val/images/1101.JPG /val/labels/1101.xml
51 | /val/images/2102.JPG /val/labels/2102.xml
52 | /val/images/5121.JPG /val/labels/5121.xml
53 | /val/images/6061.JPG /val/labels/6061.xml
54 | /val/images/6161.JPG /val/labels/6161.xml
55 | /val/images/1012.JPG /val/labels/1012.xml
56 | /val/images/5091.JPG /val/labels/5091.xml
57 | /val/images/6052.JPG /val/labels/6052.xml
58 | /val/images/4022.JPG /val/labels/4022.xml
59 | /val/images/5062.JPG /val/labels/5062.xml
60 | /val/images/2202.JPG /val/labels/2202.xml
61 | /val/images/3071.JPG /val/labels/3071.xml
62 | /val/images/1102.JPG /val/labels/1102.xml
63 | /val/images/2022.JPG /val/labels/2022.xml
64 | /val/images/5171.JPG /val/labels/5171.xml
65 | /val/images/6022.JPG /val/labels/6022.xml
66 | /val/images/1121.JPG /val/labels/1121.xml
67 | /val/images/6162.JPG /val/labels/6162.xml
68 | /val/images/4121.JPG /val/labels/4121.xml
69 | /val/images/3072.JPG /val/labels/3072.xml
70 | /val/images/6051.JPG /val/labels/6051.xml
71 | /val/images/4172.JPG /val/labels/4172.xml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TasselNetv2+
2 |
3 |
4 |
5 |
6 |
7 | This repository includes the official implementation of TasselNetv2+ for plant counting, presented in paper:
8 |
9 | **TasselNetv2+: A Fast Implementation for High-Throughput Plant Counting from High-Resolution RGB Imagery**
10 |
11 | Frontiers in Plant Science, 2020
12 |
13 | [Hao Lu](https://sites.google.com/site/poppinace/) and Zhiguo Cao
14 |
15 |
16 | ## Highlights
17 | - **Highly Efficient:** TasselNetv2+ runs an order of magnitude faster than [TasselNetv2](https://link.springer.com/article/10.1186/s13007-019-0537-2) with around 30fps on image resolution of 1980×1080 on a single GTX 1070;
18 | - **Effective:** It retrains the same level of counting accuracy compared to its counterpart TasselNetv2;
19 | - **Easy to Use:** Pretrained plant counting models are included in this repository.
20 |
21 |
22 | ## Installation
23 | The code has been tested on Python 3.7.4 and PyTorch 1.2.0. Please follow the official instructions to configure your environment. See other required packages in `requirements.txt`.
24 |
25 | ## Prepare Your Data
26 | **Wheat Ears Counting**
27 | 1. Download the Wheat Ears Counting (WEC) dataset from: [Google Drive (2.5 GB)](https://drive.google.com/open?id=1XHcTqRWf-xD-WuBeJ0C9KfIN8ye6cnSs). I have reorganized the data, the credit of this dataset belongs to [this repository](https://github.com/simonMadec/Wheat-Ears-Detection-Dataset).
28 | 2. Unzip the dataset and move it into the `./data` folder, the path structure should look like this:
29 | ````
30 | $./data/wheat_ears_counting_dataset
31 | ├──── train
32 | │ ├──── images
33 | │ └──── labels
34 | ├──── val
35 | │ ├──── images
36 | │ └──── labels
37 | ````
38 |
39 | **Maize Tassels Counting**
40 | 1. Download the Maize Tassels Counting (MTC) dataset from: [Google Drive (1.8 GB)](https://drive.google.com/open?id=1IyGpYMS_6eClco2zpHKzW5QDUuZqfVFJ)
41 | 2. Unzip the dataset and move it into the `./data` folder, the path structure should look like this:
42 | ````
43 | $./data/maize_counting_dataset
44 | ├──── trainval
45 | │ ├──── images
46 | │ └──── labels
47 | ├──── test
48 | │ ├──── images
49 | │ └──── labels
50 | ````
51 |
52 | **Sorghum Heads Counting**
53 | 1. Download the Sorghum Heads Counting (SHC) dataset from: [Google Drive (152 MB)](https://drive.google.com/open?id=1msk8vYDyKdrYDq5zU1kKWOxfmgaXpy-P). The credit of this dataset belongs to [this repository](https://github.com/oceam/sorghum-head). I only use the two subsets that have dotted annotations available.
54 | 2. Unzip the dataset and move it into the `./data` folder, the path structure should look like this:
55 | ````
56 | $./data/sorghum_head_counting_dataset
57 | ├──── original
58 | │ ├──── dataset1
59 | │ └──── dataset2
60 | ├──── labeled
61 | │ ├──── dataset1
62 | │ └──── dataset2
63 | ````
64 |
65 | ## Inference
66 | Run the following command to reproduce our results of TasselNetv2+ on the WEC/MTC/SHC dataset:
67 |
68 | sh config/hl_wec_eval.sh
69 |
70 | sh config/hl_mtc_eval.sh
71 |
72 | sh config/hl_shc_eval.sh
73 |
74 | - Results are saved in the path `./results/$dataset/$exp/$epoch`.
75 |
76 | ## Training
77 | Run the following command to train TasselNetv2+ on the on the WEC/MTC/SHC dataset:
78 |
79 | sh config/hl_wec_train.sh
80 |
81 | sh config/hl_mtc_train.sh
82 |
83 | sh config/hl_shc_train.sh
84 |
85 |
86 | ## Play with Your Own Dataset
87 | To use this framework on your own dataset, you may need to:
88 | 1. Annotate your data with dotted annotations. I recommend the [VGG Image Annotator](http://www.robots.ox.ac.uk/~vgg/software/via/);
89 | 2. Generate train/validation list following the example in `gen_trainval_list.py`;
90 | 3. Write your dataloader following example codes in `hldataset.py`;
91 | 4. Compute the mean and standard deviation of RGB on the training set;
92 | 5. Create a new entry in the `dataset_list` in `hltrainval.py`;
93 | 6. Create a new `your_dataset.sh` following examples in `./config` and modify the hyper-parameters (e.g., batch size, crop size) if applicable.
94 | 7. Train and test your model. Happy playing:)
95 |
96 | ## Citation
97 | If you find this work or code useful for your research, please cite:
98 | ```
99 | @article{lu2020tasselnetv2plus,
100 | title={TasselNetV2+: A fast implementation for high-throughput plant counting from high-resolution RGB imagery},
101 | author={Lu, Hao and Cao, Zhiguo},
102 | journal={Frontiers in Plant Science},
103 | year={2020}
104 | }
105 |
106 | @article{xiong2019tasselnetv2,
107 | title={TasselNetv2: in-field counting of wheat spikes with context-augmented local regression networks},
108 | author={Xiong, Haipeng and Cao, Zhiguo and Lu, Hao and Madec, Simon and Liu, Liang and Shen, Chunhua},
109 | journal={Plant Methods},
110 | volume={15},
111 | number={1},
112 | pages={150},
113 | year={2019},
114 | publisher={Springer}
115 | }
116 | ```
117 |
118 | ## Permission
119 | This code is only for non-commercial purposes. Please contact Hao Lu (hlu@hust.edu.cn) if you are interested in commerial use.
120 |
--------------------------------------------------------------------------------
/snapshots/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs8_epoch500.txt:
--------------------------------------------------------------------------------
1 | image_scale : 0.00392156862745098
2 | image_mean : [[[0.4051 0.4392 0.2344]]]
3 | image_std : [[[0.2569 0.262 0.2287]]]
4 | scales : [0.7, 1, 1.3]
5 | shorter_side : 224
6 | data_dir : ./data/wheat_ears_counting_dataset
7 | dataset : wec
8 | exp : tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs10_epoch500
9 | data_list : ./data/wheat_ears_counting_dataset/train.txt
10 | data_val_list : ./data/wheat_ears_counting_dataset/val.txt
11 | restore_from : ./snapshots/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs10_epoch500/model_best.pth.tar
12 | snapshot_dir : ./snapshots/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs10_epoch500
13 | result_dir : ./results/wec/tasselnetv2plus_rf110_i64o8_r0167_crop512_lr-2_bs10_epoch500
14 | save_output : False
15 | input_size : 64
16 | output_stride : 8
17 | resize_ratio : 0.1667
18 | model : tasselnetv2plus
19 | width_mult : 1.0
20 | use_pretrained : False
21 | freeze_bn : False
22 | sync_bn : False
23 | use_nonlinear : False
24 | use_context : False
25 | use_squeeze : False
26 | optimizer : sgd
27 | batch_size : 8
28 | milestones : [200, 400]
29 | crop_size : (512, 512)
30 | evaluate_only : False
31 | learning_rate : 0.01
32 | momentum : 0.95
33 | weight_decay : 0.0005
34 | mult : 1
35 | num_epochs : 500
36 | num_workers : 0
37 | print_every : 10
38 | random_seed : 2020
39 | val_every : 10
40 | epoch: 10, mae: 55.73, mse: 59.27, rmae: 41.13%, rmse: 42.95%, r2: 0.1498
41 | epoch: 20, mae: 22.46, mse: 27.32, rmae: 17.31%, rmse: 21.22%, r2: 0.2067
42 | epoch: 30, mae: 26.42, mse: 30.22, rmae: 19.66%, rmse: 22.12%, r2: 0.4955
43 | epoch: 40, mae: 26.10, mse: 28.73, rmae: 19.45%, rmse: 21.26%, r2: 0.6330
44 | epoch: 50, mae: 9.60, mse: 12.50, rmae: 7.22%, rmse: 9.45%, r2: 0.7562
45 | epoch: 60, mae: 59.74, mse: 63.42, rmae: 45.56%, rmse: 48.78%, r2: 0.3599
46 | epoch: 70, mae: 37.38, mse: 38.69, rmae: 28.28%, rmse: 29.39%, r2: 0.7938
47 | epoch: 80, mae: 20.19, mse: 23.86, rmae: 15.32%, rmse: 18.20%, r2: 0.6817
48 | epoch: 90, mae: 6.61, mse: 8.23, rmae: 5.03%, rmse: 6.27%, r2: 0.8099
49 | epoch: 100, mae: 15.40, mse: 16.61, rmae: 11.40%, rmse: 12.15%, r2: 0.8267
50 | epoch: 110, mae: 9.28, mse: 11.57, rmae: 7.10%, rmse: 8.94%, r2: 0.8604
51 | epoch: 120, mae: 32.80, mse: 35.75, rmae: 25.25%, rmse: 28.03%, r2: 0.5412
52 | epoch: 130, mae: 15.92, mse: 17.21, rmae: 11.82%, rmse: 12.60%, r2: 0.8691
53 | epoch: 140, mae: 13.56, mse: 15.18, rmae: 10.27%, rmse: 11.64%, r2: 0.8719
54 | epoch: 150, mae: 31.30, mse: 31.92, rmae: 23.49%, rmse: 23.94%, r2: 0.8889
55 | epoch: 160, mae: 17.83, mse: 19.52, rmae: 13.52%, rmse: 14.92%, r2: 0.8012
56 | epoch: 170, mae: 19.86, mse: 21.79, rmae: 14.93%, rmse: 16.46%, r2: 0.8380
57 | epoch: 180, mae: 13.61, mse: 14.98, rmae: 10.14%, rmse: 11.12%, r2: 0.8836
58 | epoch: 190, mae: 14.10, mse: 17.43, rmae: 10.85%, rmse: 13.43%, r2: 0.7943
59 | epoch: 200, mae: 6.50, mse: 8.42, rmae: 4.96%, rmse: 6.46%, r2: 0.8696
60 | epoch: 210, mae: 8.54, mse: 10.19, rmae: 6.45%, rmse: 7.80%, r2: 0.9013
61 | epoch: 220, mae: 6.20, mse: 7.58, rmae: 4.70%, rmse: 5.84%, r2: 0.9144
62 | epoch: 230, mae: 7.11, mse: 8.47, rmae: 5.29%, rmse: 6.31%, r2: 0.9136
63 | epoch: 240, mae: 5.78, mse: 7.04, rmae: 4.34%, rmse: 5.32%, r2: 0.9177
64 | epoch: 250, mae: 5.94, mse: 7.30, rmae: 4.53%, rmse: 5.65%, r2: 0.9102
65 | epoch: 260, mae: 8.57, mse: 9.79, rmae: 6.36%, rmse: 7.26%, r2: 0.9158
66 | epoch: 270, mae: 8.55, mse: 9.94, rmae: 6.44%, rmse: 7.58%, r2: 0.9175
67 | epoch: 280, mae: 11.03, mse: 12.29, rmae: 8.29%, rmse: 9.29%, r2: 0.9186
68 | epoch: 290, mae: 6.50, mse: 7.87, rmae: 4.89%, rmse: 5.95%, r2: 0.9150
69 | epoch: 300, mae: 4.59, mse: 5.66, rmae: 3.45%, rmse: 4.24%, r2: 0.9151
70 | epoch: 310, mae: 6.29, mse: 7.65, rmae: 4.69%, rmse: 5.74%, r2: 0.9214
71 | epoch: 320, mae: 6.30, mse: 7.69, rmae: 4.75%, rmse: 5.84%, r2: 0.9142
72 | epoch: 330, mae: 5.24, mse: 6.44, rmae: 3.96%, rmse: 4.91%, r2: 0.9132
73 | epoch: 340, mae: 4.80, mse: 5.70, rmae: 3.65%, rmse: 4.36%, r2: 0.9202
74 | epoch: 350, mae: 7.60, mse: 9.02, rmae: 5.72%, rmse: 6.89%, r2: 0.9073
75 | epoch: 360, mae: 5.61, mse: 6.87, rmae: 4.21%, rmse: 5.18%, r2: 0.9144
76 | epoch: 370, mae: 14.10, mse: 15.20, rmae: 10.62%, rmse: 11.49%, r2: 0.9105
77 | epoch: 380, mae: 5.44, mse: 6.64, rmae: 4.17%, rmse: 5.12%, r2: 0.9111
78 | epoch: 390, mae: 5.01, mse: 6.10, rmae: 3.80%, rmse: 4.63%, r2: 0.9105
79 | epoch: 400, mae: 15.86, mse: 16.83, rmae: 11.92%, rmse: 12.69%, r2: 0.9110
80 | epoch: 410, mae: 6.91, mse: 8.27, rmae: 5.19%, rmse: 6.27%, r2: 0.9165
81 | epoch: 420, mae: 6.47, mse: 7.77, rmae: 4.85%, rmse: 5.87%, r2: 0.9162
82 | epoch: 430, mae: 5.70, mse: 6.99, rmae: 4.27%, rmse: 5.28%, r2: 0.9155
83 | epoch: 440, mae: 5.49, mse: 6.74, rmae: 4.15%, rmse: 5.17%, r2: 0.9176
84 | epoch: 450, mae: 8.29, mse: 9.65, rmae: 6.20%, rmse: 7.26%, r2: 0.9143
85 | epoch: 460, mae: 6.48, mse: 7.81, rmae: 4.88%, rmse: 5.93%, r2: 0.9193
86 | epoch: 470, mae: 5.69, mse: 6.94, rmae: 4.28%, rmse: 5.27%, r2: 0.9179
87 | epoch: 480, mae: 7.49, mse: 8.81, rmae: 5.61%, rmse: 6.66%, r2: 0.9162
88 | epoch: 490, mae: 5.07, mse: 6.18, rmae: 3.83%, rmse: 4.71%, r2: 0.9177
89 | epoch: 500, mae: 7.57, mse: 8.95, rmae: 5.69%, rmse: 6.78%, r2: 0.9167
90 | best mae: 4.59, best mse: 5.66, best_rmae: 3.45, best_rmse: 4.24, best_r2: 0.9151
91 | overall best mae: 4.59, overall best mse: 5.66, overall best_rmae: 3.45, overall best_rmse: 4.24, overall best_r2: 0.9214
92 |
--------------------------------------------------------------------------------
/snapshots/mtc/tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500/tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500.txt:
--------------------------------------------------------------------------------
1 | image_scale : 0.00392156862745098
2 | image_mean : [[[0.3859 0.4905 0.2895]]]
3 | image_std : [[[0.1718 0.1712 0.1518]]]
4 | scales : [0.7, 1, 1.3]
5 | shorter_side : 224
6 | data_dir : ./data/maize_counting_dataset
7 | dataset : mtc
8 | exp : tasselnetv2plus_normalinit_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500
9 | data_list : ./data/maize_counting_dataset/train.txt
10 | data_val_list : ./data/maize_counting_dataset/test.txt
11 | restore_from : ./snapshots/mtc/tasselnetv2plus_normalinit_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500/model_best.pth.tar
12 | snapshot_dir : ./snapshots/mtc/tasselnetv2plus_normalinit_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500
13 | result_dir : ./results/mtc/tasselnetv2plus_normalinit_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500
14 | save_output : False
15 | input_size : 64
16 | output_stride : 8
17 | resize_ratio : 0.125
18 | model : tasselnetv2plus
19 | width_mult : 1.0
20 | use_pretrained : False
21 | freeze_bn : False
22 | sync_bn : False
23 | use_nonlinear : False
24 | use_context : False
25 | use_squeeze : False
26 | optimizer : sgd
27 | batch_size : 9
28 | milestones : [200, 400]
29 | crop_size : (256, 256)
30 | evaluate_only : False
31 | learning_rate : 0.01
32 | momentum : 0.95
33 | weight_decay : 0.0005
34 | mult : 1
35 | num_epochs : 500
36 | num_workers : 0
37 | print_every : 10
38 | random_seed : 2020
39 | val_every : 10
40 | epoch: 10, mae: 8.63, mse: 14.44, relerr: 62.70%, relerr10: 22.07%, r2: 0.7150
41 | epoch: 20, mae: 11.16, mse: 15.78, relerr: 43.29%, relerr10: 35.18%, r2: 0.8175
42 | epoch: 30, mae: 14.76, mse: 21.61, relerr: 52.63%, relerr10: 44.74%, r2: 0.6139
43 | epoch: 40, mae: 8.72, mse: 14.23, relerr: 39.13%, relerr10: 23.12%, r2: 0.7990
44 | epoch: 50, mae: 16.41, mse: 23.71, relerr: 85.35%, relerr10: 39.88%, r2: 0.5240
45 | epoch: 60, mae: 17.25, mse: 19.73, relerr: 190.12%, relerr10: 51.44%, r2: 0.7861
46 | epoch: 70, mae: 8.46, mse: 12.55, relerr: 69.19%, relerr10: 23.82%, r2: 0.8175
47 | epoch: 80, mae: 11.28, mse: 17.45, relerr: 40.59%, relerr10: 38.37%, r2: 0.7293
48 | epoch: 90, mae: 13.38, mse: 18.58, relerr: 58.30%, relerr10: 36.34%, r2: 0.7935
49 | epoch: 100, mae: 11.40, mse: 15.84, relerr: 42.02%, relerr10: 36.31%, r2: 0.8323
50 | epoch: 110, mae: 11.83, mse: 17.81, relerr: 41.31%, relerr10: 39.48%, r2: 0.7446
51 | epoch: 120, mae: 8.48, mse: 11.62, relerr: 107.78%, relerr10: 26.57%, r2: 0.8379
52 | epoch: 130, mae: 6.12, mse: 9.62, relerr: 44.27%, relerr10: 17.42%, r2: 0.8823
53 | epoch: 140, mae: 6.45, mse: 9.86, relerr: 29.65%, relerr10: 20.40%, r2: 0.8844
54 | epoch: 150, mae: 7.68, mse: 12.73, relerr: 48.76%, relerr10: 20.25%, r2: 0.8309
55 | epoch: 160, mae: 6.04, mse: 9.11, relerr: 42.24%, relerr10: 18.50%, r2: 0.8841
56 | epoch: 170, mae: 6.22, mse: 8.95, relerr: 57.06%, relerr10: 17.26%, r2: 0.9062
57 | epoch: 180, mae: 8.02, mse: 14.07, relerr: 57.70%, relerr10: 19.45%, r2: 0.7666
58 | epoch: 190, mae: 7.54, mse: 11.11, relerr: 51.27%, relerr10: 22.86%, r2: 0.8334
59 | epoch: 200, mae: 9.34, mse: 14.16, relerr: 35.75%, relerr10: 27.77%, r2: 0.8446
60 | epoch: 210, mae: 5.61, mse: 10.14, relerr: 30.57%, relerr10: 17.31%, r2: 0.8704
61 | epoch: 220, mae: 6.35, mse: 10.65, relerr: 30.48%, relerr10: 19.50%, r2: 0.8771
62 | epoch: 230, mae: 5.38, mse: 9.51, relerr: 30.67%, relerr10: 16.03%, r2: 0.8841
63 | epoch: 240, mae: 5.71, mse: 10.06, relerr: 31.46%, relerr10: 16.90%, r2: 0.8765
64 | epoch: 250, mae: 5.55, mse: 10.05, relerr: 30.30%, relerr10: 15.84%, r2: 0.8767
65 | epoch: 260, mae: 5.89, mse: 10.63, relerr: 30.71%, relerr10: 16.56%, r2: 0.8707
66 | epoch: 270, mae: 5.75, mse: 10.01, relerr: 32.54%, relerr10: 16.37%, r2: 0.8785
67 | epoch: 280, mae: 5.77, mse: 9.94, relerr: 29.51%, relerr10: 16.51%, r2: 0.8939
68 | epoch: 290, mae: 5.30, mse: 9.50, relerr: 31.07%, relerr10: 14.57%, r2: 0.8900
69 | epoch: 300, mae: 6.27, mse: 10.51, relerr: 34.51%, relerr10: 17.63%, r2: 0.8783
70 | epoch: 310, mae: 5.09, mse: 9.06, relerr: 33.81%, relerr10: 14.09%, r2: 0.8880
71 | epoch: 320, mae: 5.16, mse: 9.09, relerr: 33.77%, relerr10: 14.54%, r2: 0.8926
72 | epoch: 330, mae: 5.93, mse: 10.70, relerr: 30.02%, relerr10: 17.17%, r2: 0.8641
73 | epoch: 340, mae: 5.37, mse: 9.95, relerr: 28.80%, relerr10: 15.50%, r2: 0.8748
74 | epoch: 350, mae: 5.87, mse: 10.64, relerr: 33.15%, relerr10: 16.06%, r2: 0.8594
75 | epoch: 360, mae: 5.81, mse: 9.96, relerr: 30.95%, relerr10: 15.51%, r2: 0.8951
76 | epoch: 370, mae: 6.62, mse: 11.25, relerr: 35.86%, relerr10: 17.99%, r2: 0.8696
77 | epoch: 380, mae: 5.68, mse: 10.50, relerr: 32.99%, relerr10: 15.58%, r2: 0.8603
78 | epoch: 390, mae: 5.34, mse: 9.74, relerr: 31.56%, relerr10: 14.74%, r2: 0.8725
79 | epoch: 400, mae: 5.46, mse: 9.66, relerr: 29.28%, relerr10: 15.28%, r2: 0.8939
80 | epoch: 410, mae: 5.89, mse: 10.64, relerr: 28.17%, relerr10: 17.17%, r2: 0.8688
81 | epoch: 420, mae: 5.55, mse: 10.15, relerr: 30.31%, relerr10: 15.38%, r2: 0.8741
82 | epoch: 430, mae: 5.50, mse: 10.24, relerr: 30.20%, relerr10: 15.26%, r2: 0.8677
83 | epoch: 440, mae: 5.53, mse: 10.13, relerr: 31.68%, relerr10: 14.97%, r2: 0.8751
84 | epoch: 450, mae: 5.56, mse: 10.36, relerr: 30.76%, relerr10: 14.98%, r2: 0.8693
85 | epoch: 460, mae: 5.44, mse: 9.88, relerr: 31.79%, relerr10: 14.66%, r2: 0.8814
86 | epoch: 470, mae: 5.50, mse: 10.03, relerr: 32.37%, relerr10: 14.67%, r2: 0.8778
87 | epoch: 480, mae: 5.52, mse: 10.09, relerr: 33.53%, relerr10: 14.71%, r2: 0.8753
88 | epoch: 490, mae: 5.96, mse: 10.62, relerr: 30.87%, relerr10: 16.10%, r2: 0.8741
89 | epoch: 500, mae: 5.58, mse: 10.22, relerr: 29.42%, relerr10: 15.37%, r2: 0.8765
90 | best mae: 5.09, best mse: 9.06, best_relerr: 33.81, best_relerr10: 14.09, best_r2: 0.8880
91 | overall best mae: 5.09, overall best mse: 8.95, overall best_relerr: 28.17, overall best_relerr10: 14.09, overall best_r2: 0.9062
92 |
--------------------------------------------------------------------------------
/snapshots/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500.txt:
--------------------------------------------------------------------------------
1 | image_scale : 0.00392156862745098
2 | image_mean : [[[0.3714 0.3609 0.2386]]]
3 | image_std : [[[0.2705 0.2567 0.2161]]]
4 | scales : [0.7, 1, 1.3]
5 | shorter_side : 224
6 | data_dir : ./data/sorghum_head_counting_dataset
7 | dataset : shc
8 | exp : tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500
9 | data_list : ./data/sorghum_head_counting_dataset/dataset2_train.txt
10 | data_val_list : ./data/sorghum_head_counting_dataset/dataset2_test.txt
11 | restore_from : ./snapshots/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500/model_best.pth.tar
12 | snapshot_dir : ./snapshots/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500
13 | result_dir : ./results/shc/tasselnetv2plus_dataset2_rf110_i64o8_r1_crop1024_lr-2_bs10_epoch500
14 | save_output : False
15 | input_size : 64
16 | output_stride : 8
17 | resize_ratio : 1.0
18 | model : tasselnetv2plus
19 | width_mult : 1.0
20 | use_pretrained : False
21 | freeze_bn : False
22 | sync_bn : False
23 | use_nonlinear : False
24 | use_context : False
25 | use_squeeze : False
26 | optimizer : sgd
27 | batch_size : 5
28 | milestones : [200, 400]
29 | crop_size : (256, 1024)
30 | evaluate_only : False
31 | learning_rate : 0.01
32 | momentum : 0.95
33 | weight_decay : 0.0005
34 | mult : 1
35 | num_epochs : 500
36 | num_workers : 0
37 | print_every : 4
38 | random_seed : 2020
39 | val_every : 10
40 | epoch: 10, mae: 41.29, mse: 46.29, relerr: 41.09%, relerr10: 41.09%, r2: 0.0691
41 | epoch: 20, mae: 11.44, mse: 12.30, relerr: 11.18%, relerr10: 11.18%, r2: 0.4129
42 | epoch: 30, mae: 39.58, mse: 39.99, relerr: 39.08%, relerr10: 39.08%, r2: 0.3798
43 | epoch: 40, mae: 22.82, mse: 23.76, relerr: 22.41%, relerr10: 22.41%, r2: 0.2649
44 | epoch: 50, mae: 43.68, mse: 44.28, relerr: 43.37%, relerr10: 43.37%, r2: 0.5122
45 | epoch: 60, mae: 33.05, mse: 34.23, relerr: 32.60%, relerr10: 32.60%, r2: 0.1628
46 | epoch: 70, mae: 24.90, mse: 27.40, relerr: 24.67%, relerr10: 24.67%, r2: 0.3279
47 | epoch: 80, mae: 45.99, mse: 47.63, relerr: 45.53%, relerr10: 45.53%, r2: 0.3714
48 | epoch: 90, mae: 23.05, mse: 28.55, relerr: 22.89%, relerr10: 22.89%, r2: 0.1397
49 | epoch: 100, mae: 13.39, mse: 17.55, relerr: 13.28%, relerr10: 13.28%, r2: 0.3006
50 | epoch: 110, mae: 15.50, mse: 19.12, relerr: 15.33%, relerr10: 15.33%, r2: 0.3328
51 | epoch: 120, mae: 3.58, mse: 4.78, relerr: 3.57%, relerr10: 3.57%, r2: 0.6767
52 | epoch: 130, mae: 10.46, mse: 12.84, relerr: 10.39%, relerr10: 10.39%, r2: 0.4653
53 | epoch: 140, mae: 14.22, mse: 14.92, relerr: 14.08%, relerr10: 14.08%, r2: 0.3705
54 | epoch: 150, mae: 13.82, mse: 14.90, relerr: 13.69%, relerr10: 13.69%, r2: 0.6517
55 | epoch: 160, mae: 17.76, mse: 18.84, relerr: 17.64%, relerr10: 17.64%, r2: 0.5625
56 | epoch: 170, mae: 11.72, mse: 13.31, relerr: 11.70%, relerr10: 11.70%, r2: 0.4438
57 | epoch: 180, mae: 7.93, mse: 8.79, relerr: 7.86%, relerr10: 7.86%, r2: 0.6470
58 | epoch: 190, mae: 49.86, mse: 52.81, relerr: 49.36%, relerr10: 49.36%, r2: 0.2279
59 | epoch: 200, mae: 7.45, mse: 12.08, relerr: 7.44%, relerr10: 7.44%, r2: 0.3438
60 | epoch: 210, mae: 4.44, mse: 7.03, relerr: 4.44%, relerr10: 4.44%, r2: 0.5064
61 | epoch: 220, mae: 5.59, mse: 8.52, relerr: 5.56%, relerr10: 5.56%, r2: 0.4720
62 | epoch: 230, mae: 7.24, mse: 10.56, relerr: 7.21%, relerr10: 7.21%, r2: 0.4450
63 | epoch: 240, mae: 5.67, mse: 8.64, relerr: 5.64%, relerr10: 5.64%, r2: 0.4703
64 | epoch: 250, mae: 9.52, mse: 12.68, relerr: 9.44%, relerr10: 9.44%, r2: 0.4255
65 | epoch: 260, mae: 10.70, mse: 13.29, relerr: 10.61%, relerr10: 10.61%, r2: 0.4551
66 | epoch: 270, mae: 11.42, mse: 13.68, relerr: 11.31%, relerr10: 11.31%, r2: 0.4940
67 | epoch: 280, mae: 7.11, mse: 9.60, relerr: 7.06%, relerr10: 7.06%, r2: 0.5355
68 | epoch: 290, mae: 8.06, mse: 11.13, relerr: 7.99%, relerr10: 7.99%, r2: 0.4615
69 | epoch: 300, mae: 5.74, mse: 8.46, relerr: 5.68%, relerr10: 5.68%, r2: 0.5134
70 | epoch: 310, mae: 5.50, mse: 8.85, relerr: 5.49%, relerr10: 5.49%, r2: 0.4416
71 | epoch: 320, mae: 10.52, mse: 13.70, relerr: 10.42%, relerr10: 10.42%, r2: 0.4194
72 | epoch: 330, mae: 5.66, mse: 8.59, relerr: 5.60%, relerr10: 5.60%, r2: 0.4850
73 | epoch: 340, mae: 5.21, mse: 7.46, relerr: 5.18%, relerr10: 5.18%, r2: 0.5637
74 | epoch: 350, mae: 4.21, mse: 6.45, relerr: 4.18%, relerr10: 4.18%, r2: 0.5591
75 | epoch: 360, mae: 5.18, mse: 8.13, relerr: 5.18%, relerr10: 5.18%, r2: 0.4859
76 | epoch: 370, mae: 8.50, mse: 11.80, relerr: 8.42%, relerr10: 8.42%, r2: 0.4413
77 | epoch: 380, mae: 14.24, mse: 16.45, relerr: 14.08%, relerr10: 14.08%, r2: 0.4872
78 | epoch: 390, mae: 4.61, mse: 7.21, relerr: 4.61%, relerr10: 4.61%, r2: 0.5192
79 | epoch: 400, mae: 8.65, mse: 11.75, relerr: 8.57%, relerr10: 8.57%, r2: 0.4575
80 | epoch: 410, mae: 7.96, mse: 10.68, relerr: 7.89%, relerr10: 7.89%, r2: 0.5154
81 | epoch: 420, mae: 6.87, mse: 9.60, relerr: 6.82%, relerr10: 6.82%, r2: 0.5159
82 | epoch: 430, mae: 6.66, mse: 9.32, relerr: 6.60%, relerr10: 6.60%, r2: 0.5228
83 | epoch: 440, mae: 8.05, mse: 10.71, relerr: 7.97%, relerr10: 7.97%, r2: 0.5148
84 | epoch: 450, mae: 6.86, mse: 9.48, relerr: 6.81%, relerr10: 6.81%, r2: 0.5299
85 | epoch: 460, mae: 6.90, mse: 9.78, relerr: 6.86%, relerr10: 6.86%, r2: 0.4983
86 | epoch: 470, mae: 9.23, mse: 11.75, relerr: 9.14%, relerr10: 9.14%, r2: 0.5070
87 | epoch: 480, mae: 6.56, mse: 9.08, relerr: 6.52%, relerr10: 6.52%, r2: 0.5389
88 | epoch: 490, mae: 8.32, mse: 10.90, relerr: 8.25%, relerr10: 8.25%, r2: 0.5152
89 | epoch: 500, mae: 8.80, mse: 11.62, relerr: 8.71%, relerr10: 8.71%, r2: 0.4849
90 | best mae: 3.58, best mse: 4.78, best_relerr: 3.57, best_relerr10: 3.57, best_r2: 0.6767
91 | overall best mae: 3.58, overall best mse: 4.78, overall best_relerr: 3.57, overall best_relerr10: 3.57, overall best_r2: 0.6767
92 | epoch: 120, mae: 3.58, mse: 4.78, relerr: 3.57%, relerr10: 3.57%, r2: 0.6767
93 |
--------------------------------------------------------------------------------
/hlnet.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | @author: hao lu
4 | """
5 |
6 | import torch
7 | import torch.nn as nn
8 | import torch.nn.functional as F
9 | from utils import *
10 |
11 |
12 | class Encoder(nn.Module):
13 | def __init__(self, arc='tasselnetv2plus'):
14 | super(Encoder, self).__init__()
15 | if arc == 'tasselnetv2':
16 | self.encoder = nn.Sequential(
17 | nn.Conv2d(3, 16, 3, padding=1, bias=False),
18 | nn.BatchNorm2d(16),
19 | nn.ReLU(inplace=True),
20 | nn.MaxPool2d((2, 2), stride=2),
21 | nn.Conv2d(16, 32, 3, padding=1, bias=False),
22 | nn.BatchNorm2d(32),
23 | nn.ReLU(inplace=True),
24 | nn.MaxPool2d((2, 2), stride=2),
25 | nn.Conv2d(32, 64, 3, padding=1, bias=False),
26 | nn.BatchNorm2d(64),
27 | nn.ReLU(inplace=True),
28 | nn.MaxPool2d((2, 2), stride=2),
29 | nn.Conv2d(64, 128, 3, padding=1, bias=False),
30 | nn.BatchNorm2d(128),
31 | nn.ReLU(inplace=True),
32 | nn.Conv2d(128, 128, 3, padding=1, bias=False),
33 | nn.BatchNorm2d(128),
34 | nn.ReLU(inplace=True),
35 | )
36 | elif arc == 'tasselnetv2plus':
37 | self.encoder = nn.Sequential(
38 | nn.Conv2d(3, 16, 3, padding=1, bias=False),
39 | nn.BatchNorm2d(16),
40 | nn.ReLU(inplace=True),
41 | nn.MaxPool2d((2, 2), stride=2),
42 | nn.Conv2d(16, 32, 3, padding=1, bias=False),
43 | nn.BatchNorm2d(32),
44 | nn.ReLU(inplace=True),
45 | nn.MaxPool2d((2, 2), stride=2),
46 | nn.Conv2d(32, 64, 3, padding=1, bias=False),
47 | nn.BatchNorm2d(64),
48 | nn.ReLU(inplace=True),
49 | nn.MaxPool2d((2, 2), stride=2),
50 | nn.Conv2d(64, 128, 3, padding=1, bias=False),
51 | nn.BatchNorm2d(128),
52 | nn.ReLU(inplace=True),
53 | nn.Conv2d(128, 128, 3, padding=1, bias=False),
54 | nn.BatchNorm2d(128),
55 | nn.ReLU(inplace=True)
56 | )
57 | else:
58 | raise NotImplementedError
59 |
60 | def forward(self, x):
61 | x = self.encoder(x)
62 | return x
63 |
64 |
65 | class Counter(nn.Module):
66 | def __init__(self, arc='tasselnetv2plus', input_size=64, output_stride=8):
67 | super(Counter, self).__init__()
68 | k = int(input_size / 8)
69 | avg_pool_stride = int(output_stride / 8)
70 |
71 | if arc == 'tasselnetv2':
72 | self.counter = nn.Sequential(
73 | nn.Conv2d(128, 128, (k, k), bias=False),
74 | nn.BatchNorm2d(128),
75 | nn.ReLU(inplace=True),
76 | nn.Conv2d(128, 128, 1, bias=False),
77 | nn.BatchNorm2d(128),
78 | nn.ReLU(inplace=True),
79 | nn.Conv2d(128, 1, 1)
80 | )
81 | elif arc == 'tasselnetv2plus':
82 | self.counter = nn.Sequential(
83 | nn.AvgPool2d((k, k), stride=avg_pool_stride),
84 | nn.Conv2d(128, 128, 1, bias=False),
85 | nn.BatchNorm2d(128),
86 | nn.ReLU(inplace=True),
87 | nn.Conv2d(128, 1, 1)
88 | )
89 | else:
90 | raise NotImplementedError
91 |
92 | def forward(self, x):
93 | x = self.counter(x)
94 | return x
95 |
96 |
97 | class Normalizer:
98 | @staticmethod
99 | def cpu_normalizer(x, imh, imw, insz, os):
100 | # CPU normalization
101 | bs = x.size()[0]
102 | normx = np.zeros((imh, imw))
103 | norm_vec = dense_sample2d(normx, insz, os).astype(np.float32)
104 | x = x.cpu().detach().numpy().reshape(bs, -1) * norm_vec
105 | return x
106 |
107 | @staticmethod
108 | def gpu_normalizer(x, imh, imw, insz, os):
109 | _, _, h, w = x.size()
110 | accm = torch.cuda.FloatTensor(1, insz*insz, h*w).fill_(1)
111 | accm = F.fold(accm, (imh, imw), kernel_size=insz, stride=os)
112 | accm = 1 / accm
113 | accm /= insz**2
114 | accm = F.unfold(accm, kernel_size=insz, stride=os).sum(1).view(1, 1, h, w)
115 | x *= accm
116 | return x.squeeze().cpu().detach().numpy()
117 |
118 |
119 | class CountingModels(nn.Module):
120 | def __init__(self, arc='tasselnetv2plus', input_size=64, output_stride=8):
121 | super(CountingModels, self).__init__()
122 | self.input_size = input_size
123 | self.output_stride = output_stride
124 |
125 | self.encoder = Encoder(arc)
126 | self.counter = Counter(arc, input_size, output_stride)
127 | if arc == 'tasselnetv2':
128 | self.normalizer = Normalizer.cpu_normalizer
129 | elif arc == 'tasselnetv2plus':
130 | self.normalizer = Normalizer.gpu_normalizer
131 |
132 | self.weight_init()
133 |
134 | def forward(self, x, is_normalize=True):
135 | imh, imw = x.size()[2:]
136 | x = self.encoder(x)
137 | x = self.counter(x)
138 | if is_normalize:
139 | x = self.normalizer(x, imh, imw, self.input_size, self.output_stride)
140 | return x
141 |
142 | def weight_init(self):
143 | for m in self.modules():
144 | if isinstance(m, nn.Conv2d):
145 | nn.init.normal_(m.weight, std=0.01)
146 | # nn.init.kaiming_uniform_(
147 | # m.weight,
148 | # mode='fan_in',
149 | # nonlinearity='relu'
150 | # )
151 | if m.bias is not None:
152 | nn.init.constant_(m.bias, 0)
153 | elif isinstance(m, nn.BatchNorm2d):
154 | nn.init.constant_(m.weight, 1)
155 | nn.init.constant_(m.bias, 0)
156 |
157 |
158 | if __name__ == "__main__":
159 |
160 | from time import time
161 |
162 | insz, os = 64, 8
163 | imH, imW = 1080, 1920
164 | net = CountingModels(arc='tasselnetv2plus', input_size=insz, output_stride=os).cuda()
165 | with torch.no_grad():
166 | net.eval()
167 | x = torch.randn(1, 3, imH, imW).cuda()
168 | y = net(x)
169 | print(y.shape)
170 |
171 | import numpy as np
172 |
173 | with torch.no_grad():
174 | frame_rate = np.zeros((100, 1))
175 |
176 | for i in range(100):
177 | x = torch.randn(1, 3, imH, imW).cuda()
178 | torch.cuda.synchronize()
179 | start = time()
180 |
181 | y = net(x)
182 |
183 | torch.cuda.synchronize()
184 | end = time()
185 |
186 | running_frame_rate = 1 * float(1 / (end - start))
187 | frame_rate[i] = running_frame_rate
188 | print(np.mean(frame_rate))
--------------------------------------------------------------------------------
/data/wheat_ears_counting_dataset/train.txt:
--------------------------------------------------------------------------------
1 | /train/images/2091.JPG /train/labels/2091.xml
2 | /train/images/2163.JPG /train/labels/2163.xml
3 | /train/images/2181.JPG /train/labels/2181.xml
4 | /train/images/5102.JPG /train/labels/5102.xml
5 | /train/images/2033.JPG /train/labels/2033.xml
6 | /train/images/6081.JPG /train/labels/6081.xml
7 | /train/images/5111.JPG /train/labels/5111.xml
8 | /train/images/6101.JPG /train/labels/6101.xml
9 | /train/images/4153.JPG /train/labels/4153.xml
10 | /train/images/2151.JPG /train/labels/2151.xml
11 | /train/images/6031.JPG /train/labels/6031.xml
12 | /train/images/1142.JPG /train/labels/1142.xml
13 | /train/images/2192.JPG /train/labels/2192.xml
14 | /train/images/2092.JPG /train/labels/2092.xml
15 | /train/images/6032.JPG /train/labels/6032.xml
16 | /train/images/3012.JPG /train/labels/3012.xml
17 | /train/images/5151.JPG /train/labels/5151.xml
18 | /train/images/2012.JPG /train/labels/2012.xml
19 | /train/images/6082.JPG /train/labels/6082.xml
20 | /train/images/6191.JPG /train/labels/6191.xml
21 | /train/images/5011.JPG /train/labels/5011.xml
22 | /train/images/5112.JPG /train/labels/5112.xml
23 | /train/images/3081.JPG /train/labels/3081.xml
24 | /train/images/6121.JPG /train/labels/6121.xml
25 | /train/images/6151.JPG /train/labels/6151.xml
26 | /train/images/4182.JPG /train/labels/4182.xml
27 | /train/images/4071.JPG /train/labels/4071.xml
28 | /train/images/4142.JPG /train/labels/4142.xml
29 | /train/images/5022.JPG /train/labels/5022.xml
30 | /train/images/1191.JPG /train/labels/1191.xml
31 | /train/images/2132.JPG /train/labels/2132.xml
32 | /train/images/5152.JPG /train/labels/5152.xml
33 | /train/images/4141.JPG /train/labels/4141.xml
34 | /train/images/3011.JPG /train/labels/3011.xml
35 | /train/images/5032.JPG /train/labels/5032.xml
36 | /train/images/6122.JPG /train/labels/6122.xml
37 | /train/images/4032.JPG /train/labels/4032.xml
38 | /train/images/3122.JPG /train/labels/3122.xml
39 | /train/images/4181.JPG /train/labels/4181.xml
40 | /train/images/1082.JPG /train/labels/1082.xml
41 | /train/images/5132.JPG /train/labels/5132.xml
42 | /train/images/2062.JPG /train/labels/2062.xml
43 | /train/images/5161.JPG /train/labels/5161.xml
44 | /train/images/3032.JPG /train/labels/3032.xml
45 | /train/images/2041.JPG /train/labels/2041.xml
46 | /train/images/5201.JPG /train/labels/5201.xml
47 | /train/images/1073.JPG /train/labels/1073.xml
48 | /train/images/1182.JPG /train/labels/1182.xml
49 | /train/images/4092.JPG /train/labels/4092.xml
50 | /train/images/6171.JPG /train/labels/6171.xml
51 | /train/images/1021.JPG /train/labels/1021.xml
52 | /train/images/2131.JPG /train/labels/2131.xml
53 | /train/images/3061.JPG /train/labels/3061.xml
54 | /train/images/3111.JPG /train/labels/3111.xml
55 | /train/images/3052.JPG /train/labels/3052.xml
56 | /train/images/1141.JPG /train/labels/1141.xml
57 | /train/images/5131.JPG /train/labels/5131.xml
58 | /train/images/6202.JPG /train/labels/6202.xml
59 | /train/images/1192.JPG /train/labels/1192.xml
60 | /train/images/5031.JPG /train/labels/5031.xml
61 | /train/images/1042.JPG /train/labels/1042.xml
62 | /train/images/6072.JPG /train/labels/6072.xml
63 | /train/images/6141.JPG /train/labels/6141.xml
64 | /train/images/2171.JPG /train/labels/2171.xml
65 | /train/images/2191.JPG /train/labels/2191.xml
66 | /train/images/3051.JPG /train/labels/3051.xml
67 | /train/images/3121.JPG /train/labels/3121.xml
68 | /train/images/2082.JPG /train/labels/2082.xml
69 | /train/images/5071.JPG /train/labels/5071.xml
70 | /train/images/3181.JPG /train/labels/3181.xml
71 | /train/images/4201.JPG /train/labels/4201.xml
72 | /train/images/3082.JPG /train/labels/3082.xml
73 | /train/images/4161.JPG /train/labels/4161.xml
74 | /train/images/5101.JPG /train/labels/5101.xml
75 | /train/images/6102.JPG /train/labels/6102.xml
76 | /train/images/6181.JPG /train/labels/6181.xml
77 | /train/images/1132.JPG /train/labels/1132.xml
78 | /train/images/5041.JPG /train/labels/5041.xml
79 | /train/images/4111.JPG /train/labels/4111.xml
80 | /train/images/2172.JPG /train/labels/2172.xml
81 | /train/images/4012.JPG /train/labels/4012.xml
82 | /train/images/1152.JPG /train/labels/1152.xml
83 | /train/images/5012.JPG /train/labels/5012.xml
84 | /train/images/3092.JPG /train/labels/3092.xml
85 | /train/images/2081.JPG /train/labels/2081.xml
86 | /train/images/2061.JPG /train/labels/2061.xml
87 | /train/images/1032.JPG /train/labels/1032.xml
88 | /train/images/4202.JPG /train/labels/4202.xml
89 | /train/images/1031.JPG /train/labels/1031.xml
90 | /train/images/1091.JPG /train/labels/1091.xml
91 | /train/images/3182.JPG /train/labels/3182.xml
92 | /train/images/3042.JPG /train/labels/3042.xml
93 | /train/images/1202.JPG /train/labels/1202.xml
94 | /train/images/3041.JPG /train/labels/3041.xml
95 | /train/images/6182.JPG /train/labels/6182.xml
96 | /train/images/4051.JPG /train/labels/4051.xml
97 | /train/images/4162.JPG /train/labels/4162.xml
98 | /train/images/6041.JPG /train/labels/6041.xml
99 | /train/images/1022.JPG /train/labels/1022.xml
100 | /train/images/3021.JPG /train/labels/3021.xml
101 | /train/images/5042.JPG /train/labels/5042.xml
102 | /train/images/6142.JPG /train/labels/6142.xml
103 | /train/images/2141.JPG /train/labels/2141.xml
104 | /train/images/1151.JPG /train/labels/1151.xml
105 | /train/images/5162.JPG /train/labels/5162.xml
106 | /train/images/2142.JPG /train/labels/2142.xml
107 | /train/images/2182.JPG /train/labels/2182.xml
108 | /train/images/1081.JPG /train/labels/1081.xml
109 | /train/images/1092.JPG /train/labels/1092.xml
110 | /train/images/4072.JPG /train/labels/4072.xml
111 | /train/images/4042.JPG /train/labels/4042.xml
112 | /train/images/1111.JPG /train/labels/1111.xml
113 | /train/images/2122.JPG /train/labels/2122.xml
114 | /train/images/4101.JPG /train/labels/4101.xml
115 | /train/images/3132.JPG /train/labels/3132.xml
116 | /train/images/4152.JPG /train/labels/4152.xml
117 | /train/images/4011.JPG /train/labels/4011.xml
118 | /train/images/4052.JPG /train/labels/4052.xml
119 | /train/images/6172.JPG /train/labels/6172.xml
120 | /train/images/5021.JPG /train/labels/5021.xml
121 | /train/images/4102.JPG /train/labels/4102.xml
122 | /train/images/6092.JPG /train/labels/6092.xml
123 | /train/images/4031.JPG /train/labels/4031.xml
124 | /train/images/6071.JPG /train/labels/6071.xml
125 | /train/images/3141.JPG /train/labels/3141.xml
126 | /train/images/6192.JPG /train/labels/6192.xml
127 | /train/images/4151.JPG /train/labels/4151.xml
128 | /train/images/6152.JPG /train/labels/6152.xml
129 | /train/images/3031.JPG /train/labels/3031.xml
130 | /train/images/1112.JPG /train/labels/1112.xml
131 | /train/images/6111.JPG /train/labels/6111.xml
132 | /train/images/3133.JPG /train/labels/3133.xml
133 | /train/images/3062.JPG /train/labels/3062.xml
134 | /train/images/6112.JPG /train/labels/6112.xml
135 | /train/images/5082.JPG /train/labels/5082.xml
136 | /train/images/1071.JPG /train/labels/1071.xml
137 | /train/images/5202.JPG /train/labels/5202.xml
138 | /train/images/6091.JPG /train/labels/6091.xml
139 | /train/images/3112.JPG /train/labels/3112.xml
140 | /train/images/1181.JPG /train/labels/1181.xml
141 | /train/images/1171.JPG /train/labels/1171.xml
142 | /train/images/5052.JPG /train/labels/5052.xml
143 | /train/images/3022.JPG /train/labels/3022.xml
144 | /train/images/6042.JPG /train/labels/6042.xml
145 | /train/images/4062.JPG /train/labels/4062.xml
146 | /train/images/2011.JPG /train/labels/2011.xml
147 | /train/images/5072.JPG /train/labels/5072.xml
148 | /train/images/5081.JPG /train/labels/5081.xml
149 | /train/images/4091.JPG /train/labels/4091.xml
150 | /train/images/3172.JPG /train/labels/3172.xml
151 | /train/images/6201.JPG /train/labels/6201.xml
152 | /train/images/5192.JPG /train/labels/5192.xml
153 | /train/images/5191.JPG /train/labels/5191.xml
154 | /train/images/1131.JPG /train/labels/1131.xml
155 | /train/images/3142.JPG /train/labels/3142.xml
156 | /train/images/1172.JPG /train/labels/1172.xml
157 | /train/images/3091.JPG /train/labels/3091.xml
158 | /train/images/2152.JPG /train/labels/2152.xml
159 | /train/images/3171.JPG /train/labels/3171.xml
160 | /train/images/2121.JPG /train/labels/2121.xml
161 | /train/images/4061.JPG /train/labels/4061.xml
162 | /train/images/4112.JPG /train/labels/4112.xml
163 | /train/images/1041.JPG /train/labels/1041.xml
164 | /train/images/1201.JPG /train/labels/1201.xml
165 | /train/images/4041.JPG /train/labels/4041.xml
--------------------------------------------------------------------------------
/data/maize_counting_dataset/test.txt:
--------------------------------------------------------------------------------
1 | /test/images/T0001_XM_20110807130247_01.jpg /test/labels/T0001_XM_20110807130247_01.mat
2 | /test/images/T0001_XM_20110813160244_01.jpg /test/labels/T0001_XM_20110813160244_01.mat
3 | /test/images/T0006_XM_20140811160049_01.jpg /test/labels/T0006_XM_20140811160049_01.mat
4 | /test/images/T0001_XM_20120802140257_02.jpg /test/labels/T0001_XM_20120802140257_02.mat
5 | /test/images/T0001_XM_20120801100256_02.jpg /test/labels/T0001_XM_20120801100256_02.mat
6 | /test/images/T0001_XM_20110812100243_01.jpg /test/labels/T0001_XM_20110812100243_01.mat
7 | /test/images/XAM02_YM_20150727100010_01.jpg /test/labels/XAM02_YM_20150727100010_01.mat
8 | /test/images/T0002_XM_20110728110224_01.jpg /test/labels/T0002_XM_20110728110224_01.mat
9 | /test/images/T0006_YM_20140818180046_01.jpg /test/labels/T0006_YM_20140818180046_01.mat
10 | /test/images/T0006_YM_20140818170051_01.jpg /test/labels/T0006_YM_20140818170051_01.mat
11 | /test/images/T0006_YM_20140818090047_01.jpg /test/labels/T0006_YM_20140818090047_01.mat
12 | /test/images/T0006_YM_20140816140055_01.jpg /test/labels/T0006_YM_20140816140055_01.mat
13 | /test/images/T0002_XM_20110802100228_01.jpg /test/labels/T0002_XM_20110802100228_01.mat
14 | /test/images/XAM02_YM_20150725100005_01.jpg /test/labels/XAM02_YM_20150725100005_01.mat
15 | /test/images/T0001_YM_20100803160241_01.jpg /test/labels/T0001_YM_20100803160241_01.mat
16 | /test/images/T0001_YM_20100804100235_01.jpg /test/labels/T0001_YM_20100804100235_01.mat
17 | /test/images/T0001_YM_20100804140239_01.jpg /test/labels/T0001_YM_20100804140239_01.mat
18 | /test/images/XAM05_YM_20150731160225_01.jpg /test/labels/XAM05_YM_20150731160225_01.mat
19 | /test/images/T0002_XM_20110727100223_01.jpg /test/labels/T0002_XM_20110727100223_01.mat
20 | /test/images/T0001_XM_20120805090254_02.jpg /test/labels/T0001_XM_20120805090254_02.mat
21 | /test/images/T0001_XM_20110811160245_01.jpg /test/labels/T0001_XM_20110811160245_01.mat
22 | /test/images/T0006_XM_20140809120051_01.jpg /test/labels/T0006_XM_20140809120051_01.mat
23 | /test/images/XAM05_YM_20150726160228_01.jpg /test/labels/XAM05_YM_20150726160228_01.mat
24 | /test/images/T0001_XM_20120806150256_02.jpg /test/labels/T0001_XM_20120806150256_02.mat
25 | /test/images/T0002_XM_20110802090224_01.jpg /test/labels/T0002_XM_20110802090224_01.mat
26 | /test/images/T0001_XM_20130810100251_02.jpg /test/labels/T0001_XM_20130810100251_02.mat
27 | /test/images/T0001_XM_20120802110255_02.jpg /test/labels/T0001_XM_20120802110255_02.mat
28 | /test/images/T0001_XM_20110809120248_01.jpg /test/labels/T0001_XM_20110809120248_01.mat
29 | /test/images/T0002_XM_20110802120223_01.jpg /test/labels/T0002_XM_20110802120223_01.mat
30 | /test/images/XAM05_YM_20150801160224_01.jpg /test/labels/XAM05_YM_20150801160224_01.mat
31 | /test/images/T0006_XM_20140811170049_01.jpg /test/labels/T0006_XM_20140811170049_01.mat
32 | /test/images/T0006_XM_20140808090048_01.jpg /test/labels/T0006_XM_20140808090048_01.mat
33 | /test/images/T0001_XM_20120801160256_02.jpg /test/labels/T0001_XM_20120801160256_02.mat
34 | /test/images/T0001_XM_20120805150254_02.jpg /test/labels/T0001_XM_20120805150254_02.mat
35 | /test/images/T0001_XM_20120807090254_02.jpg /test/labels/T0001_XM_20120807090254_02.mat
36 | /test/images/T0001_XM_20110808160246_01.jpg /test/labels/T0001_XM_20110808160246_01.mat
37 | /test/images/T0001_XM_20110808100247_01.jpg /test/labels/T0001_XM_20110808100247_01.mat
38 | /test/images/T0006_XM_20140812080052_01.jpg /test/labels/T0006_XM_20140812080052_01.mat
39 | /test/images/T0006_YM_20140816120051_01.jpg /test/labels/T0006_YM_20140816120051_01.mat
40 | /test/images/T0006_XM_20140813110051_01.jpg /test/labels/T0006_XM_20140813110051_01.mat
41 | /test/images/XAM02_YM_20150731100011_01.jpg /test/labels/XAM02_YM_20150731100011_01.mat
42 | /test/images/T0006_YM_20140817100046_01.jpg /test/labels/T0006_YM_20140817100046_01.mat
43 | /test/images/T0006_YM_20140818110052_01.jpg /test/labels/T0006_YM_20140818110052_01.mat
44 | /test/images/T0002_XM_20110728130225_01.jpg /test/labels/T0002_XM_20110728130225_01.mat
45 | /test/images/T0002_XM_20110729160224_01.jpg /test/labels/T0002_XM_20110729160224_01.mat
46 | /test/images/T0006_XM_20140814130054_01.jpg /test/labels/T0006_XM_20140814130054_01.mat
47 | /test/images/T0006_XM_20140813160048_01.jpg /test/labels/T0006_XM_20140813160048_01.mat
48 | /test/images/XAM05_YM_20150725160227_01.jpg /test/labels/XAM05_YM_20150725160227_01.mat
49 | /test/images/T0002_XM_20110728090224_01.jpg /test/labels/T0002_XM_20110728090224_01.mat
50 | /test/images/T0001_YM_20100808110235_01.jpg /test/labels/T0001_YM_20100808110235_01.mat
51 | /test/images/T0001_XM_20120806130253_02.jpg /test/labels/T0001_XM_20120806130253_02.mat
52 | /test/images/T0006_XM_20140815110055_01.jpg /test/labels/T0006_XM_20140815110055_01.mat
53 | /test/images/T0006_XM_20140808110052_01.jpg /test/labels/T0006_XM_20140808110052_01.mat
54 | /test/images/T0006_XM_20140810160052_01.jpg /test/labels/T0006_XM_20140810160052_01.mat
55 | /test/images/T0002_XM_20110727160223_01.jpg /test/labels/T0002_XM_20110727160223_01.mat
56 | /test/images/XAM05_YM_20150729160225_01.jpg /test/labels/XAM05_YM_20150729160225_01.mat
57 | /test/images/T0001_XM_20110813100247_01.jpg /test/labels/T0001_XM_20110813100247_01.mat
58 | /test/images/T0001_YM_20100805140235_01.jpg /test/labels/T0001_YM_20100805140235_01.mat
59 | /test/images/T0002_XM_20110730090225_01.jpg /test/labels/T0002_XM_20110730090225_01.mat
60 | /test/images/T0002_XM_20110728150223_01.jpg /test/labels/T0002_XM_20110728150223_01.mat
61 | /test/images/T0001_XM_20120805100258_02.jpg /test/labels/T0001_XM_20120805100258_02.mat
62 | /test/images/T0001_XM_20120804100258_02.jpg /test/labels/T0001_XM_20120804100258_02.mat
63 | /test/images/T0001_XM_20110809160242_01.jpg /test/labels/T0001_XM_20110809160242_01.mat
64 | /test/images/T0001_XM_20120803100257_02.jpg /test/labels/T0001_XM_20120803100257_02.mat
65 | /test/images/T0001_YM_20100805120236_01.jpg /test/labels/T0001_YM_20100805120236_01.mat
66 | /test/images/T0001_XM_20110809100242_01.jpg /test/labels/T0001_XM_20110809100242_01.mat
67 | /test/images/T0002_XM_20110802160225_01.jpg /test/labels/T0002_XM_20110802160225_01.mat
68 | /test/images/T0006_YM_20140816100050_01.jpg /test/labels/T0006_YM_20140816100050_01.mat
69 | /test/images/T0001_YM_20100806130240_01.jpg /test/labels/T0001_YM_20100806130240_01.mat
70 | /test/images/T0001_YM_20100805150240_01.jpg /test/labels/T0001_YM_20100805150240_01.mat
71 | /test/images/XAM02_YM_20150729100005_01.jpg /test/labels/XAM02_YM_20150729100005_01.mat
72 | /test/images/T0001_XM_20120803090254_02.jpg /test/labels/T0001_XM_20120803090254_02.mat
73 | /test/images/T0006_XM_20140814090050_01.jpg /test/labels/T0006_XM_20140814090050_01.mat
74 | /test/images/T0001_XM_20120804160257_02.jpg /test/labels/T0001_XM_20120804160257_02.mat
75 | /test/images/T0001_YM_20100802160235_01.jpg /test/labels/T0001_YM_20100802160235_01.mat
76 | /test/images/T0001_YM_20100803100238_01.jpg /test/labels/T0001_YM_20100803100238_01.mat
77 | /test/images/XAM05_YM_20150724160229_01.jpg /test/labels/XAM05_YM_20150724160229_01.mat
78 | /test/images/T0006_XM_20140815180047_01.jpg /test/labels/T0006_XM_20140815180047_01.mat
79 | /test/images/T0001_XM_20110811120244_01.jpg /test/labels/T0001_XM_20110811120244_01.mat
80 | /test/images/XAM05_YM_20150723160224_01.jpg /test/labels/XAM05_YM_20150723160224_01.mat
81 | /test/images/T0001_YM_20100807100236_01.jpg /test/labels/T0001_YM_20100807100236_01.mat
82 | /test/images/T0002_XM_20110730130223_01.jpg /test/labels/T0002_XM_20110730130223_01.mat
83 | /test/images/T0002_XM_20110801150224_01.jpg /test/labels/T0002_XM_20110801150224_01.mat
84 | /test/images/T0001_XM_20120805140252_02.jpg /test/labels/T0001_XM_20120805140252_02.mat
85 | /test/images/T0006_XM_20140812110051_01.jpg /test/labels/T0006_XM_20140812110051_01.mat
86 | /test/images/T0006_XM_20140814110050_01.jpg /test/labels/T0006_XM_20140814110050_01.mat
87 | /test/images/T0001_XM_20130805130253_02.jpg /test/labels/T0001_XM_20130805130253_02.mat
88 | /test/images/T0002_XM_20110802110223_01.jpg /test/labels/T0002_XM_20110802110223_01.mat
89 | /test/images/T0001_XM_20110807100242_01.jpg /test/labels/T0001_XM_20110807100242_01.mat
90 | /test/images/T0001_YM_20100807090237_01.jpg /test/labels/T0001_YM_20100807090237_01.mat
91 | /test/images/T0006_XM_20140809180047_01.jpg /test/labels/T0006_XM_20140809180047_01.mat
92 | /test/images/T0001_XM_20130804080253_02.jpg /test/labels/T0001_XM_20130804080253_02.mat
93 | /test/images/T0002_XM_20110730160224_01.jpg /test/labels/T0002_XM_20110730160224_01.mat
94 | /test/images/T0006_XM_20140814150051_01.jpg /test/labels/T0006_XM_20140814150051_01.mat
95 | /test/images/T0001_YM_20100809160239_01.jpg /test/labels/T0001_YM_20100809160239_01.mat
96 | /test/images/T0001_XM_20110812160245_01.jpg /test/labels/T0001_XM_20110812160245_01.mat
97 | /test/images/T0001_YM_20100806110235_01.jpg /test/labels/T0001_YM_20100806110235_01.mat
98 | /test/images/T0001_XM_20130808110252_02.jpg /test/labels/T0001_XM_20130808110252_02.mat
99 | /test/images/T0006_XM_20140809100048_01.jpg /test/labels/T0006_XM_20140809100048_01.mat
100 | /test/images/T0001_YM_20100806160239_01.jpg /test/labels/T0001_YM_20100806160239_01.mat
101 | /test/images/XAM02_YM_20150802100007_01.jpg /test/labels/XAM02_YM_20150802100007_01.mat
102 | /test/images/XAM02_YM_20150805100009_01.jpg /test/labels/XAM02_YM_20150805100009_01.mat
103 | /test/images/T0001_XM_20120803120254_02.jpg /test/labels/T0001_XM_20120803120254_02.mat
104 | /test/images/T0002_XM_20110730110224_01.jpg /test/labels/T0002_XM_20110730110224_01.mat
105 | /test/images/T0001_YM_20100806150239_01.jpg /test/labels/T0001_YM_20100806150239_01.mat
106 | /test/images/T0001_YM_20100805100237_01.jpg /test/labels/T0001_YM_20100805100237_01.mat
107 | /test/images/XAM02_YM_20150804100010_01.jpg /test/labels/XAM02_YM_20150804100010_01.mat
108 | /test/images/T0002_XM_20110731100223_01.jpg /test/labels/T0002_XM_20110731100223_01.mat
109 | /test/images/T0001_XM_20120802160252_02.jpg /test/labels/T0001_XM_20120802160252_02.mat
110 | /test/images/T0001_XM_20120805130255_02.jpg /test/labels/T0001_XM_20120805130255_02.mat
111 | /test/images/T0001_XM_20130806120253_02.jpg /test/labels/T0001_XM_20130806120253_02.mat
112 | /test/images/T0002_XM_20110801160224_01.jpg /test/labels/T0002_XM_20110801160224_01.mat
113 | /test/images/T0001_XM_20130809120253_02.jpg /test/labels/T0001_XM_20130809120253_02.mat
114 | /test/images/T0006_YM_20140817160050_01.jpg /test/labels/T0006_YM_20140817160050_01.mat
115 | /test/images/XAM02_YM_20150803100005_01.jpg /test/labels/XAM02_YM_20150803100005_01.mat
116 | /test/images/XAM02_YM_20150801100008_01.jpg /test/labels/XAM02_YM_20150801100008_01.mat
117 | /test/images/T0006_XM_20140808160048_01.jpg /test/labels/T0006_XM_20140808160048_01.mat
118 | /test/images/T0001_YM_20100807160235_01.jpg /test/labels/T0001_YM_20100807160235_01.mat
119 | /test/images/XAM02_YM_20150726100009_01.jpg /test/labels/XAM02_YM_20150726100009_01.mat
120 | /test/images/T0002_XM_20110730100225_01.jpg /test/labels/T0002_XM_20110730100225_01.mat
121 | /test/images/T0001_YM_20100809130240_01.jpg /test/labels/T0001_YM_20100809130240_01.mat
122 | /test/images/T0006_XM_20140811100052_01.jpg /test/labels/T0006_XM_20140811100052_01.mat
123 | /test/images/XAM05_YM_20150802160229_01.jpg /test/labels/XAM05_YM_20150802160229_01.mat
124 | /test/images/T0001_YM_20100809100235_01.jpg /test/labels/T0001_YM_20100809100235_01.mat
125 | /test/images/T0001_YM_20100809140240_01.jpg /test/labels/T0001_YM_20100809140240_01.mat
126 | /test/images/XAM05_YM_20150803160225_01.jpg /test/labels/XAM05_YM_20150803160225_01.mat
127 | /test/images/T0001_YM_20100806100235_01.jpg /test/labels/T0001_YM_20100806100235_01.mat
128 | /test/images/T0001_YM_20100808100235_01.jpg /test/labels/T0001_YM_20100808100235_01.mat
129 | /test/images/T0006_XM_20140810180047_01.jpg /test/labels/T0006_XM_20140810180047_01.mat
130 | /test/images/T0006_XM_20140811130049_01.jpg /test/labels/T0006_XM_20140811130049_01.mat
131 | /test/images/T0001_YM_20100802100241_01.jpg /test/labels/T0001_YM_20100802100241_01.mat
132 | /test/images/T0002_XM_20110729110232_01.jpg /test/labels/T0002_XM_20110729110232_01.mat
133 | /test/images/T0001_XM_20110810160246_01.jpg /test/labels/T0001_XM_20110810160246_01.mat
134 | /test/images/T0001_XM_20110810100242_01.jpg /test/labels/T0001_XM_20110810100242_01.mat
135 | /test/images/T0001_YM_20100804160240_01.jpg /test/labels/T0001_YM_20100804160240_01.mat
136 | /test/images/T0001_YM_20100806140240_01.jpg /test/labels/T0001_YM_20100806140240_01.mat
137 | /test/images/T0006_XM_20140812140053_01.jpg /test/labels/T0006_XM_20140812140053_01.mat
138 | /test/images/T0001_XM_20110811100244_01.jpg /test/labels/T0001_XM_20110811100244_01.mat
139 | /test/images/T0006_YM_20140816160047_01.jpg /test/labels/T0006_YM_20140816160047_01.mat
140 | /test/images/T0001_XM_20120805110255_02.jpg /test/labels/T0001_XM_20120805110255_02.mat
141 | /test/images/T0001_YM_20100806090236_01.jpg /test/labels/T0001_YM_20100806090236_01.mat
142 | /test/images/T0001_XM_20120805120252_02.jpg /test/labels/T0001_XM_20120805120252_02.mat
143 | /test/images/T0001_YM_20100807110237_01.jpg /test/labels/T0001_YM_20100807110237_01.mat
144 | /test/images/T0001_XM_20110813090243_01.jpg /test/labels/T0001_XM_20110813090243_01.mat
145 | /test/images/T0006_XM_20140812170051_01.jpg /test/labels/T0006_XM_20140812170051_01.mat
146 | /test/images/T0001_XM_20110811140245_01.jpg /test/labels/T0001_XM_20110811140245_01.mat
147 | /test/images/T0006_XM_20140810150050_01.jpg /test/labels/T0006_XM_20140810150050_01.mat
148 | /test/images/XAM02_YM_20150728100006_01.jpg /test/labels/XAM02_YM_20150728100006_01.mat
149 | /test/images/T0001_XM_20120807150255_02.jpg /test/labels/T0001_XM_20120807150255_02.mat
150 | /test/images/XAM05_YM_20150730160225_01.jpg /test/labels/XAM05_YM_20150730160225_01.mat
151 | /test/images/T0001_YM_20100806120242_01.jpg /test/labels/T0001_YM_20100806120242_01.mat
152 | /test/images/T0001_YM_20100805130235_01.jpg /test/labels/T0001_YM_20100805130235_01.mat
153 | /test/images/XAM05_YM_20150727160224_01.jpg /test/labels/XAM05_YM_20150727160224_01.mat
154 | /test/images/T0006_YM_20140818130051_01.jpg /test/labels/T0006_YM_20140818130051_01.mat
155 | /test/images/T0006_YM_20140817130050_01.jpg /test/labels/T0006_YM_20140817130050_01.mat
156 | /test/images/XAM02_YM_20150730100009_01.jpg /test/labels/XAM02_YM_20150730100009_01.mat
157 | /test/images/T0002_XM_20110801090223_01.jpg /test/labels/T0002_XM_20110801090223_01.mat
158 | /test/images/T0002_XM_20110801100224_01.jpg /test/labels/T0002_XM_20110801100224_01.mat
159 | /test/images/T0006_XM_20140810120053_01.jpg /test/labels/T0006_XM_20140810120053_01.mat
160 | /test/images/T0001_YM_20100805160240_01.jpg /test/labels/T0001_YM_20100805160240_01.mat
161 | /test/images/T0001_XM_20110812130242_01.jpg /test/labels/T0001_XM_20110812130242_01.mat
162 | /test/images/T0006_XM_20140813140046_01.jpg /test/labels/T0006_XM_20140813140046_01.mat
163 | /test/images/T0006_XM_20140808140052_01.jpg /test/labels/T0006_XM_20140808140052_01.mat
164 | /test/images/T0006_XM_20140809140048_01.jpg /test/labels/T0006_XM_20140809140048_01.mat
165 | /test/images/T0001_XM_20130807100253_02.jpg /test/labels/T0001_XM_20130807100253_02.mat
166 | /test/images/T0001_XM_20130803160252_02.jpg /test/labels/T0001_XM_20130803160252_02.mat
167 | /test/images/T0006_XM_20140810090049_01.jpg /test/labels/T0006_XM_20140810090049_01.mat
168 | /test/images/T0001_XM_20120805160256_02.jpg /test/labels/T0001_XM_20120805160256_02.mat
169 | /test/images/T0001_YM_20100808130241_01.jpg /test/labels/T0001_YM_20100808130241_01.mat
170 | /test/images/T0006_XM_20140809160052_01.jpg /test/labels/T0006_XM_20140809160052_01.mat
171 | /test/images/T0002_XM_20110731160223_01.jpg /test/labels/T0002_XM_20110731160223_01.mat
172 | /test/images/XAM05_YM_20150728150224_01.jpg /test/labels/XAM05_YM_20150728150224_01.mat
173 | /test/images/T0006_XM_20140815140051_01.jpg /test/labels/T0006_XM_20140815140051_01.mat
174 | /test/images/T0006_YM_20140818150054_01.jpg /test/labels/T0006_YM_20140818150054_01.mat
175 | /test/images/T0001_XM_20120803160256_02.jpg /test/labels/T0001_XM_20120803160256_02.mat
--------------------------------------------------------------------------------
/hldataset.py:
--------------------------------------------------------------------------------
1 | """
2 | @author: hao lu
3 | """
4 |
5 | import os
6 | import json
7 | import matplotlib.pyplot as plt
8 | import matplotlib.cm as cm
9 | import pandas as pd
10 | import random
11 | import numpy as np
12 | from PIL import Image
13 | import cv2
14 | import h5py
15 | import scipy.io as sio
16 | from scipy.ndimage.filters import gaussian_filter
17 | from skimage import util
18 | from skimage.measure import label
19 | from skimage.measure import regionprops
20 | import xml.etree.ElementTree as ET
21 |
22 | import torch
23 | from torch.utils.data import Dataset
24 | from torchvision import transforms
25 | import torch.nn.functional as F
26 |
27 |
28 | def read_image(x):
29 | img_arr = np.array(Image.open(x))
30 | if len(img_arr.shape) == 2: # grayscale
31 | img_arr = np.tile(img_arr, [3, 1, 1]).transpose(1, 2, 0)
32 | return img_arr
33 |
34 |
35 | class RandomCrop(object):
36 | def __init__(self, output_size):
37 | assert isinstance(output_size, (int, tuple))
38 | self.output_size = output_size
39 |
40 | def __call__(self, sample):
41 |
42 | image, target, gtcount = sample['image'], sample['target'], sample['gtcount']
43 | h, w = image.shape[:2]
44 |
45 | if isinstance(self.output_size, tuple):
46 | new_h = min(self.output_size[0], h)
47 | new_w = min(self.output_size[1], w)
48 | assert (new_h, new_w) == self.output_size
49 | else:
50 | crop_size = min(self.output_size, h, w)
51 | assert crop_size == self.output_size
52 | new_h = new_w = crop_size
53 | if gtcount > 0:
54 | mask = target > 0
55 | ch, cw = int(np.ceil(new_h / 2)), int(np.ceil(new_w / 2))
56 | mask_center = np.zeros((h, w), dtype=np.uint8)
57 | mask_center[ch:h-ch+1, cw:w-cw+1] = 1
58 | mask = (mask & mask_center)
59 | idh, idw = np.where(mask == 1)
60 | if len(idh) != 0:
61 | ids = random.choice(range(len(idh)))
62 | hc, wc = idh[ids], idw[ids]
63 | top, left = hc-ch, wc-cw
64 | else:
65 | top = np.random.randint(0, h-new_h+1)
66 | left = np.random.randint(0, w-new_w+1)
67 | else:
68 | top = np.random.randint(0, h-new_h+1)
69 | left = np.random.randint(0, w-new_w+1)
70 |
71 | image = image[top:top+new_h, left:left+new_w, :]
72 | target = target[top:top+new_h, left:left+new_w]
73 |
74 | return {'image': image, 'target': target, 'gtcount': gtcount}
75 |
76 |
77 | class RandomFlip(object):
78 | def __init__(self):
79 | pass
80 |
81 | def __call__(self, sample):
82 | image, target, gtcount = sample['image'], sample['target'], sample['gtcount']
83 | do_mirror = np.random.randint(2)
84 | if do_mirror:
85 | image = cv2.flip(image, 1)
86 | target = cv2.flip(target, 1)
87 | return {'image': image, 'target': target, 'gtcount': gtcount}
88 |
89 |
90 | class Normalize(object):
91 |
92 | def __init__(self, scale, mean, std):
93 | self.scale = scale
94 | self.mean = mean
95 | self.std = std
96 |
97 | def __call__(self, sample):
98 | image, target, gtcount = sample['image'], sample['target'], sample['gtcount']
99 | image, target = image.astype('float32'), target.astype('float32')
100 |
101 | # pixel normalization
102 | image = (self.scale * image - self.mean) / self.std
103 |
104 | image, target = image.astype('float32'), target.astype('float32')
105 |
106 | return {'image': image, 'target': target, 'gtcount': gtcount}
107 |
108 |
109 | class ZeroPadding(object):
110 | def __init__(self, psize=32):
111 | self.psize = psize
112 |
113 | def __call__(self, sample):
114 | psize = self.psize
115 |
116 | image, target, gtcount = sample['image'], sample['target'], sample['gtcount']
117 | h,w = image.size()[-2:]
118 | ph,pw = (psize-h%psize),(psize-w%psize)
119 | # print(ph,pw)
120 |
121 | (pl, pr) = (pw//2, pw-pw//2) if pw != psize else (0, 0)
122 | (pt, pb) = (ph//2, ph-ph//2) if ph != psize else (0, 0)
123 | if (ph!=psize) or (pw!=psize):
124 | tmp_pad = [pl, pr, pt, pb]
125 | # print(tmp_pad)
126 | image = F.pad(image,tmp_pad)
127 | target = F.pad(target,tmp_pad)
128 |
129 | return {'image': image, 'target': target, 'gtcount': gtcount}
130 |
131 |
132 | class ToTensor(object):
133 | """Convert ndarrays in sample to Tensors."""
134 |
135 | def __init__(self):
136 | pass
137 |
138 | def __call__(self, sample):
139 | # swap color axis
140 | # numpy image: H x W x C
141 | # torch image: C X H X W
142 | image, target, gtcount = sample['image'], sample['target'], sample['gtcount']
143 | image = image.transpose((2, 0, 1))
144 | target = np.expand_dims(target, axis=2)
145 | target = target.transpose((2, 0, 1))
146 | image, target = torch.from_numpy(image), torch.from_numpy(target)
147 | return {'image': image, 'target': target, 'gtcount': gtcount}
148 |
149 |
150 | class MaizeTasselDataset(Dataset):
151 | def __init__(self, data_dir, data_list, ratio, train=True, transform=None):
152 | self.data_dir = data_dir
153 | self.data_list = [name.split('\t') for name in open(data_list).read().splitlines()]
154 | self.ratio = ratio
155 | self.train = train
156 | self.transform = transform
157 | self.image_list = []
158 |
159 | # store images and generate ground truths
160 | self.images = {}
161 | self.targets = {}
162 | self.gtcounts = {}
163 | self.dotimages = {}
164 |
165 | def bbs2points(self, bbs):
166 | points = []
167 | for bb in bbs:
168 | x1, y1, w, h = [float(b) for b in bb]
169 | x2, y2 = x1+w-1, y1+h-1
170 | x, y = np.round((x1+x2)/2).astype(np.int32), np.round((y1+y2)/2).astype(np.int32)
171 | points.append([x, y])
172 | return points
173 |
174 | def __len__(self):
175 | return len(self.data_list)
176 |
177 | def __getitem__(self, idx):
178 | file_name = self.data_list[idx]
179 | self.image_list.append(file_name[0])
180 | if file_name[0] not in self.images:
181 | image = read_image(self.data_dir+file_name[0])
182 | annotation = sio.loadmat(self.data_dir+file_name[1])
183 | h, w = image.shape[:2]
184 | nh = int(np.ceil(h * self.ratio))
185 | nw = int(np.ceil(w * self.ratio))
186 | image = cv2.resize(image, (nw, nh), interpolation = cv2.INTER_CUBIC)
187 | target = np.zeros((nh, nw), dtype=np.float32)
188 | dotimage = image.copy()
189 | if annotation['annotation'][0][0][1] is not None:
190 | bbs = annotation['annotation'][0][0][1]
191 | gtcount = bbs.shape[0]
192 | pts = self.bbs2points(bbs)
193 | for pt in pts:
194 | pt[0], pt[1] = int(pt[0] * self.ratio), int(pt[1] * self.ratio)
195 | target[pt[1], pt[0]] = 1
196 | cv2.circle(dotimage, (pt[0], pt[1]), int(24 * self.ratio) , (255, 0, 0), -1)
197 | else:
198 | gtcount = 0
199 | target = gaussian_filter(target, 80 * self.ratio)
200 |
201 | # plt.imshow(target, cmap=cm.jet)
202 | # plt.show()
203 | # print(target.sum())
204 |
205 | self.images.update({file_name[0]:image})
206 | self.targets.update({file_name[0]:target})
207 | self.gtcounts.update({file_name[0]:gtcount})
208 | self.dotimages.update({file_name[0]:dotimage})
209 |
210 |
211 | sample = {
212 | 'image': self.images[file_name[0]],
213 | 'target': self.targets[file_name[0]],
214 | 'gtcount': self.gtcounts[file_name[0]]
215 | }
216 |
217 | if self.transform:
218 | sample = self.transform(sample)
219 |
220 | return sample
221 |
222 |
223 | class WhearEarDataset(Dataset):
224 | def __init__(self, data_dir, data_list, ratio, train=True, transform=None):
225 | self.data_dir = data_dir
226 | self.data_list = [name.split('\t') for name in open(data_list).read().splitlines()]
227 | self.ratio = ratio
228 | self.train = train
229 | self.transform = transform
230 | self.image_list = []
231 |
232 | # store images and generate ground truths
233 | self.images = {}
234 | self.targets = {}
235 | self.gtcounts = {}
236 | self.dotimages = {}
237 |
238 | def parsexml(self, xml):
239 | tree = ET.parse(xml)
240 | root = tree.getroot()
241 | bbs = []
242 | for bb in root.iter('bndbox'):
243 | xmin = int(bb.find('xmin').text)
244 | ymin = int(bb.find('ymin').text)
245 | xmax = int(bb.find('xmax').text)
246 | ymax = int(bb.find('ymax').text)
247 | bbs.append([xmin, ymin, xmax, ymax])
248 | return bbs
249 |
250 | def bbs2points(self, bbs):
251 | points = []
252 | for bb in bbs:
253 | x1, y1, x2, y2 = [float(b) for b in bb]
254 | x, y = np.round((x1+x2)/2).astype(np.int32), np.round((y1+y2)/2).astype(np.int32)
255 | points.append([x, y])
256 | return points
257 |
258 | def __len__(self):
259 | return len(self.data_list)
260 |
261 | def __getitem__(self, idx):
262 | file_name = self.data_list[idx]
263 | self.image_list.append(file_name[0])
264 | if file_name[0] not in self.images:
265 | image = read_image(self.data_dir+file_name[0])
266 | bbs = self.parsexml(self.data_dir+file_name[1])
267 | h, w = image.shape[:2]
268 | nh = int(np.ceil(h * self.ratio))
269 | nw = int(np.ceil(w * self.ratio))
270 | image = cv2.resize(image, (nw, nh), interpolation = cv2.INTER_CUBIC)
271 | target = np.zeros((nh, nw), dtype=np.float32)
272 | dotimage = image.copy()
273 | if bbs is not None:
274 | gtcount = len(bbs)
275 | pts = self.bbs2points(bbs)
276 | for pt in pts:
277 | pt[0], pt[1] = int(pt[0] * self.ratio), int(pt[1] * self.ratio)
278 | target[pt[1], pt[0]] = 1
279 | cv2.circle(dotimage, (pt[0], pt[1]), 6, (255, 0, 0), -1)
280 | else:
281 | gtcount = 0
282 | target = gaussian_filter(target, 40 * self.ratio)
283 |
284 | # cmap = plt.cm.get_cmap('jet')
285 | # target_show = target / (target.max() + 1e-12)
286 | # target_show = cmap(target_show) * 255.
287 | # target_show = 0.5 * image + 0.5 * target_show[:, :, 0:3]
288 | # plt.imshow(target_show.astype(np.uint8))
289 | # plt.show()
290 | # print(target.sum())
291 |
292 | # plt.imshow(dotimage.astype(np.uint8))
293 | # plt.show()
294 |
295 | self.images.update({file_name[0]:image})
296 | self.targets.update({file_name[0]:target})
297 | self.gtcounts.update({file_name[0]:gtcount})
298 | self.dotimages.update({file_name[0]:dotimage})
299 |
300 |
301 | sample = {
302 | 'image': self.images[file_name[0]],
303 | 'target': self.targets[file_name[0]],
304 | 'gtcount': self.gtcounts[file_name[0]]
305 | }
306 |
307 | if self.transform:
308 | sample = self.transform(sample)
309 |
310 | return sample
311 |
312 |
313 | class SorghumHeadDataset(Dataset):
314 | def __init__(self, data_dir, data_list, ratio, train=True, transform=None):
315 | self.data_dir = data_dir
316 | self.data_list = [name.split('\t') for name in open(data_list).read().splitlines()]
317 | self.ratio = ratio
318 | self.train = train
319 | self.transform = transform
320 | self.image_list = []
321 |
322 | # store images and generate ground truths
323 | self.images = {}
324 | self.targets = {}
325 | self.gtcounts = {}
326 | self.dotimages = {}
327 |
328 | def __len__(self):
329 | return len(self.data_list)
330 |
331 | def __getitem__(self, idx):
332 | file_name = self.data_list[idx]
333 | self.image_list.append(file_name[0])
334 | if file_name[0] not in self.images:
335 | image = read_image(self.data_dir+file_name[0])
336 | annotations = read_image(self.data_dir+file_name[1])
337 | annotations = util.img_as_ubyte(annotations[:, :, 0]) == 0
338 | annotations = label(annotations, connectivity=annotations.ndim)
339 | annotations = regionprops(annotations)
340 |
341 | h, w = image.shape[:2]
342 | nh = int(np.ceil(h * self.ratio))
343 | nw = int(np.ceil(w * self.ratio))
344 | image = cv2.resize(image, (nw, nh), interpolation = cv2.INTER_CUBIC)
345 | target = np.zeros((nh, nw), dtype=np.float32)
346 | dotimage = image.copy()
347 | if annotations is not None:
348 | gtcount = len(annotations)
349 | for annotation in annotations:
350 | pt = annotation.centroid
351 | x, y = int(pt[0] * self.ratio), int(pt[1] * self.ratio)
352 | target[x, y] = 1
353 | cv2.circle(dotimage, (y, x), 6, (255, 0, 0), -1)
354 | else:
355 | gtcount = 0
356 | target = gaussian_filter(target, 8 * self.ratio)
357 |
358 | # cmap = plt.cm.get_cmap('jet')
359 | # target_show = target / (target.max() + 1e-12)
360 | # target_show = cmap(target_show) * 255.
361 | # target_show = 0.5 * image + 0.5 * target_show[:, :, 0:3]
362 | # plt.imshow(target_show.astype(np.uint8))
363 | # plt.show()
364 | # print(target.sum())
365 |
366 | # plt.imshow(dotimage.astype(np.uint8))
367 | # plt.show()
368 |
369 | self.images.update({file_name[0]:image})
370 | self.targets.update({file_name[0]:target})
371 | self.gtcounts.update({file_name[0]:gtcount})
372 | self.dotimages.update({file_name[0]:dotimage})
373 |
374 |
375 | sample = {
376 | 'image': self.images[file_name[0]],
377 | 'target': self.targets[file_name[0]],
378 | 'gtcount': self.gtcounts[file_name[0]]
379 | }
380 |
381 | if self.transform:
382 | sample = self.transform(sample)
383 |
384 | return sample
385 |
386 |
387 | if __name__=='__main__':
388 |
389 | dataset = WhearEarDataset(
390 | data_dir='./data/wheat_ears_counting_dataset',
391 | data_list='./data/wheat_ears_counting_dataset/train.txt',
392 | ratio=0.167,
393 | train=True,
394 | transform=transforms.Compose([
395 | ToTensor()]
396 | )
397 | )
398 |
399 | dataloader = torch.utils.data.DataLoader(
400 | dataset,
401 | batch_size=1,
402 | shuffle=False,
403 | num_workers=0
404 | )
405 |
406 | print(len(dataloader))
407 | mean = 0.
408 | std = 0.
409 | for i, data in enumerate(dataloader, 0):
410 | images, targets = data['image'], data['target']
411 | bs = images.size(0)
412 | images = images.view(bs, images.size(1), -1).float()
413 | mean += images.mean(2).sum(0)
414 | std += images.std(2).sum(0)
415 | print(images.size())
416 | print(i)
417 | mean /= len(dataloader)
418 | std /= len(dataloader)
419 | print(mean/255.)
420 | print(std/255.)
--------------------------------------------------------------------------------
/data/maize_counting_dataset/train.txt:
--------------------------------------------------------------------------------
1 | /trainval/images/T0002_XM_20120805160221_01.jpg /trainval/labels/T0002_XM_20120805160221_01.mat
2 | /trainval/images/T0001_XM_20120805120252_01.jpg /trainval/labels/T0001_XM_20120805120252_01.mat
3 | /trainval/images/T0001_XM_20110811160246_02.jpg /trainval/labels/T0001_XM_20110811160246_02.mat
4 | /trainval/images/T0002_YM_20100817110218_01.jpg /trainval/labels/T0002_YM_20100817110218_01.mat
5 | /trainval/images/T0001_XM_20110812160246_02.jpg /trainval/labels/T0001_XM_20110812160246_02.mat
6 | /trainval/images/XAM01_YM_20150802100255_01.jpg /trainval/labels/XAM01_YM_20150802100255_01.mat
7 | /trainval/images/T0001_XM_20110814130246_02.jpg /trainval/labels/T0001_XM_20110814130246_02.mat
8 | /trainval/images/XAM01_YM_20150804100259_01.jpg /trainval/labels/XAM01_YM_20150804100259_01.mat
9 | /trainval/images/T0001_XM_20110812100244_02.jpg /trainval/labels/T0001_XM_20110812100244_02.mat
10 | /trainval/images/T0002_XM_20120802160222_01.jpg /trainval/labels/T0002_XM_20120802160222_01.mat
11 | /trainval/images/T0001_YM_20100809160240_02.jpg /trainval/labels/T0001_YM_20100809160240_02.mat
12 | /trainval/images/T0002_YM_20100820100221_01.jpg /trainval/labels/T0002_YM_20100820100221_01.mat
13 | /trainval/images/T0001_YM_20100807090237_02.jpg /trainval/labels/T0001_YM_20100807090237_02.mat
14 | /trainval/images/T0002_YM_20100815160218_01.jpg /trainval/labels/T0002_YM_20100815160218_01.mat
15 | /trainval/images/T0001_YM_20100803100239_02.jpg /trainval/labels/T0001_YM_20100803100239_02.mat
16 | /trainval/images/T0001_XM_20120805130255_01.jpg /trainval/labels/T0001_XM_20120805130255_01.mat
17 | /trainval/images/T0002_YM_20100817090218_01.jpg /trainval/labels/T0002_YM_20100817090218_01.mat
18 | /trainval/images/T0001_XM_20120807120256_01.jpg /trainval/labels/T0001_XM_20120807120256_01.mat
19 | /trainval/images/T0001_YM_20100808110236_02.jpg /trainval/labels/T0001_YM_20100808110236_02.mat
20 | /trainval/images/T0001_XM_20120809130255_01.jpg /trainval/labels/T0001_XM_20120809130255_01.mat
21 | /trainval/images/T0001_XM_20120808140252_01.jpg /trainval/labels/T0001_XM_20120808140252_01.mat
22 | /trainval/images/T0002_YM_20100816100220_01.jpg /trainval/labels/T0002_YM_20100816100220_01.mat
23 | /trainval/images/T0002_XM_20120806090222_01.jpg /trainval/labels/T0002_XM_20120806090222_01.mat
24 | /trainval/images/T0002_YM_20100811130220_01.jpg /trainval/labels/T0002_YM_20100811130220_01.mat
25 | /trainval/images/T0001_XM_20120803100255_01.jpg /trainval/labels/T0001_XM_20120803100255_01.mat
26 | /trainval/images/T0001_XM_20110813090243_02.jpg /trainval/labels/T0001_XM_20110813090243_02.mat
27 | /trainval/images/T0002_YM_20100809110218_01.jpg /trainval/labels/T0002_YM_20100809110218_01.mat
28 | /trainval/images/T0001_YM_20100802160236_02.jpg /trainval/labels/T0001_YM_20100802160236_02.mat
29 | /trainval/images/T0001_YM_20100808140237_02.jpg /trainval/labels/T0001_YM_20100808140237_02.mat
30 | /trainval/images/T0002_XM_20120804140223_01.jpg /trainval/labels/T0002_XM_20120804140223_01.mat
31 | /trainval/images/T0001_XM_20130807100253_01.jpg /trainval/labels/T0001_XM_20130807100253_01.mat
32 | /trainval/images/T0006_XM_20120815100308_01.jpg /trainval/labels/T0006_XM_20120815100308_01.mat
33 | /trainval/images/T0001_XM_20110811090244_02.jpg /trainval/labels/T0001_XM_20110811090244_02.mat
34 | /trainval/images/T0002_YM_20100814100220_01.jpg /trainval/labels/T0002_YM_20100814100220_01.mat
35 | /trainval/images/T0002_YM_20100816160218_01.jpg /trainval/labels/T0002_YM_20100816160218_01.mat
36 | /trainval/images/T0001_XM_20110809150249_02.jpg /trainval/labels/T0001_XM_20110809150249_02.mat
37 | /trainval/images/T0002_XM_20120802120222_01.jpg /trainval/labels/T0002_XM_20120802120222_01.mat
38 | /trainval/images/T0002_XM_20120805100222_01.jpg /trainval/labels/T0002_XM_20120805100222_01.mat
39 | /trainval/images/T0001_XM_20110813100248_02.jpg /trainval/labels/T0001_XM_20110813100248_02.mat
40 | /trainval/images/T0002_YM_20100823100222_01.jpg /trainval/labels/T0002_YM_20100823100222_01.mat
41 | /trainval/images/T0001_XM_20120804140256_01.jpg /trainval/labels/T0001_XM_20120804140256_01.mat
42 | /trainval/images/T0002_XM_20120802110223_01.jpg /trainval/labels/T0002_XM_20120802110223_01.mat
43 | /trainval/images/T0001_XM_20130803160251_01.jpg /trainval/labels/T0001_XM_20130803160251_01.mat
44 | /trainval/images/T0002_YM_20100730140218_01.jpg /trainval/labels/T0002_YM_20100730140218_01.mat
45 | /trainval/images/T0001_XM_20120803130257_01.jpg /trainval/labels/T0001_XM_20120803130257_01.mat
46 | /trainval/images/T0002_XM_20120804100222_01.jpg /trainval/labels/T0002_XM_20120804100222_01.mat
47 | /trainval/images/T0001_YM_20100806130242_02.jpg /trainval/labels/T0001_YM_20100806130242_02.mat
48 | /trainval/images/XAM01_YM_20150728100255_01.jpg /trainval/labels/XAM01_YM_20150728100255_01.mat
49 | /trainval/images/T0001_XM_20120809110250_01.jpg /trainval/labels/T0001_XM_20120809110250_01.mat
50 | /trainval/images/T0001_XM_20120805160256_01.jpg /trainval/labels/T0001_XM_20120805160256_01.mat
51 | /trainval/images/T0002_YM_20100731120218_01.jpg /trainval/labels/T0002_YM_20100731120218_01.mat
52 | /trainval/images/T0002_YM_20100819100220_01.jpg /trainval/labels/T0002_YM_20100819100220_01.mat
53 | /trainval/images/T0002_YM_20100808120218_01.jpg /trainval/labels/T0002_YM_20100808120218_01.mat
54 | /trainval/images/T0002_YM_20100820160219_01.jpg /trainval/labels/T0002_YM_20100820160219_01.mat
55 | /trainval/images/T0001_XM_20120805110254_01.jpg /trainval/labels/T0001_XM_20120805110254_01.mat
56 | /trainval/images/T0002_YM_20100818100222_01.jpg /trainval/labels/T0002_YM_20100818100222_01.mat
57 | /trainval/images/T0001_XM_20120809120253_01.jpg /trainval/labels/T0001_XM_20120809120253_01.mat
58 | /trainval/images/T0001_YM_20100809100237_02.jpg /trainval/labels/T0001_YM_20100809100237_02.mat
59 | /trainval/images/T0002_XM_20120801160222_01.jpg /trainval/labels/T0002_XM_20120801160222_01.mat
60 | /trainval/images/T0001_XM_20120808120253_01.jpg /trainval/labels/T0001_XM_20120808120253_01.mat
61 | /trainval/images/T0001_XM_20120808150253_01.jpg /trainval/labels/T0001_XM_20120808150253_01.mat
62 | /trainval/images/XAM01_YM_20150801100257_01.jpg /trainval/labels/XAM01_YM_20150801100257_01.mat
63 | /trainval/images/T0002_YM_20100729100220_01.jpg /trainval/labels/T0002_YM_20100729100220_01.mat
64 | /trainval/images/T0001_XM_20120801160256_01.jpg /trainval/labels/T0001_XM_20120801160256_01.mat
65 | /trainval/images/T0002_YM_20100822090219_01.jpg /trainval/labels/T0002_YM_20100822090219_01.mat
66 | /trainval/images/T0002_YM_20100821100220_01.jpg /trainval/labels/T0002_YM_20100821100220_01.mat
67 | /trainval/images/T0001_YM_20100806120243_02.jpg /trainval/labels/T0001_YM_20100806120243_02.mat
68 | /trainval/images/XAM01_YM_20150731100257_01.jpg /trainval/labels/XAM01_YM_20150731100257_01.mat
69 | /trainval/images/T0001_XM_20120803140255_01.jpg /trainval/labels/T0001_XM_20120803140255_01.mat
70 | /trainval/images/T0002_YM_20100819090220_01.jpg /trainval/labels/T0002_YM_20100819090220_01.mat
71 | /trainval/images/T0002_XM_20120806120222_01.jpg /trainval/labels/T0002_XM_20120806120222_01.mat
72 | /trainval/images/T0001_XM_20110811100245_02.jpg /trainval/labels/T0001_XM_20110811100245_02.mat
73 | /trainval/images/T0002_XM_20120803150221_01.jpg /trainval/labels/T0002_XM_20120803150221_01.mat
74 | /trainval/images/T0001_XM_20120805150253_01.jpg /trainval/labels/T0001_XM_20120805150253_01.mat
75 | /trainval/images/T0002_YM_20100816120219_01.jpg /trainval/labels/T0002_YM_20100816120219_01.mat
76 | /trainval/images/XAM01_YM_20150729100258_01.jpg /trainval/labels/XAM01_YM_20150729100258_01.mat
77 | /trainval/images/T0001_YM_20100802100242_02.jpg /trainval/labels/T0001_YM_20100802100242_02.mat
78 | /trainval/images/T0002_YM_20100814160219_01.jpg /trainval/labels/T0002_YM_20100814160219_01.mat
79 | /trainval/images/T0002_XM_20120805130223_01.jpg /trainval/labels/T0002_XM_20120805130223_01.mat
80 | /trainval/images/T0006_XM_20120809100305_01.jpg /trainval/labels/T0006_XM_20120809100305_01.mat
81 | /trainval/images/T0002_YM_20100816140221_01.jpg /trainval/labels/T0002_YM_20100816140221_01.mat
82 | /trainval/images/T0002_YM_20100823160222_01.jpg /trainval/labels/T0002_YM_20100823160222_01.mat
83 | /trainval/images/T0001_XM_20110815120244_02.jpg /trainval/labels/T0001_XM_20110815120244_02.mat
84 | /trainval/images/T0001_XM_20110812130243_02.jpg /trainval/labels/T0001_XM_20110812130243_02.mat
85 | /trainval/images/T0001_YM_20100807100238_02.jpg /trainval/labels/T0001_YM_20100807100238_02.mat
86 | /trainval/images/T0001_XM_20120809090253_01.jpg /trainval/labels/T0001_XM_20120809090253_01.mat
87 | /trainval/images/T0001_YM_20100806160240_02.jpg /trainval/labels/T0001_YM_20100806160240_02.mat
88 | /trainval/images/T0002_XM_20120807160222_01.jpg /trainval/labels/T0002_XM_20120807160222_01.mat
89 | /trainval/images/T0002_YM_20100810160221_01.jpg /trainval/labels/T0002_YM_20100810160221_01.mat
90 | /trainval/images/T0006_XM_20120807160304_01.jpg /trainval/labels/T0006_XM_20120807160304_01.mat
91 | /trainval/images/T0001_YM_20100805140236_02.jpg /trainval/labels/T0001_YM_20100805140236_02.mat
92 | /trainval/images/T0006_XM_20120808160306_01.jpg /trainval/labels/T0006_XM_20120808160306_01.mat
93 | /trainval/images/XAM01_YM_20150726100258_01.jpg /trainval/labels/XAM01_YM_20150726100258_01.mat
94 | /trainval/images/T0002_XM_20120803090221_01.jpg /trainval/labels/T0002_XM_20120803090221_01.mat
95 | /trainval/images/T0001_XM_20120803160255_01.jpg /trainval/labels/T0001_XM_20120803160255_01.mat
96 | /trainval/images/T0001_XM_20110814160244_02.jpg /trainval/labels/T0001_XM_20110814160244_02.mat
97 | /trainval/images/XAM01_YM_20150803110256_01.jpg /trainval/labels/XAM01_YM_20150803110256_01.mat
98 | /trainval/images/T0001_YM_20100806090236_02.jpg /trainval/labels/T0001_YM_20100806090236_02.mat
99 | /trainval/images/T0002_YM_20100821090220_01.jpg /trainval/labels/T0002_YM_20100821090220_01.mat
100 | /trainval/images/T0002_YM_20100821140220_01.jpg /trainval/labels/T0002_YM_20100821140220_01.mat
101 | /trainval/images/T0001_YM_20100805150241_02.jpg /trainval/labels/T0001_YM_20100805150241_02.mat
102 | /trainval/images/T0006_XM_20120815160306_01.jpg /trainval/labels/T0006_XM_20120815160306_01.mat
103 | /trainval/images/T0006_XM_20120810140308_01.jpg /trainval/labels/T0006_XM_20120810140308_01.mat
104 | /trainval/images/T0001_YM_20100803160242_02.jpg /trainval/labels/T0001_YM_20100803160242_02.mat
105 | /trainval/images/T0001_YM_20100804100237_02.jpg /trainval/labels/T0001_YM_20100804100237_02.mat
106 | /trainval/images/T0002_XM_20120801100222_01.jpg /trainval/labels/T0002_XM_20120801100222_01.mat
107 | /trainval/images/T0002_YM_20100815100220_01.jpg /trainval/labels/T0002_YM_20100815100220_01.mat
108 | /trainval/images/T0002_XM_20120803160221_01.jpg /trainval/labels/T0002_XM_20120803160221_01.mat
109 | /trainval/images/T0006_XM_20120813100305_01.jpg /trainval/labels/T0006_XM_20120813100305_01.mat
110 | /trainval/images/T0006_XM_20120809130643_01.jpg /trainval/labels/T0006_XM_20120809130643_01.mat
111 | /trainval/images/T0001_XM_20120806130252_01.jpg /trainval/labels/T0001_XM_20120806130252_01.mat
112 | /trainval/images/T0001_YM_20100805100238_02.jpg /trainval/labels/T0001_YM_20100805100238_02.mat
113 | /trainval/images/T0002_YM_20100808140219_01.jpg /trainval/labels/T0002_YM_20100808140219_01.mat
114 | /trainval/images/XAM01_YM_20150727100256_01.jpg /trainval/labels/XAM01_YM_20150727100256_01.mat
115 | /trainval/images/T0001_YM_20100804160241_02.jpg /trainval/labels/T0001_YM_20100804160241_02.mat
116 | /trainval/images/T0006_XM_20120811100308_01.jpg /trainval/labels/T0006_XM_20120811100308_01.mat
117 | /trainval/images/T0001_XM_20120809100255_01.jpg /trainval/labels/T0001_XM_20120809100255_01.mat
118 | /trainval/images/T0001_XM_20130809120252_01.jpg /trainval/labels/T0001_XM_20130809120252_01.mat
119 | /trainval/images/T0001_XM_20120807160253_01.jpg /trainval/labels/T0001_XM_20120807160253_01.mat
120 | /trainval/images/T0001_XM_20120805090254_01.jpg /trainval/labels/T0001_XM_20120805090254_01.mat
121 | /trainval/images/T0001_YM_20100803150236_02.jpg /trainval/labels/T0001_YM_20100803150236_02.mat
122 | /trainval/images/T0001_YM_20100806100236_02.jpg /trainval/labels/T0001_YM_20100806100236_02.mat
123 | /trainval/images/T0006_XM_20120808100307_01.jpg /trainval/labels/T0006_XM_20120808100307_01.mat
124 | /trainval/images/T0002_YM_20100817150218_01.jpg /trainval/labels/T0002_YM_20100817150218_01.mat
125 | /trainval/images/T0001_XM_20130810100251_01.jpg /trainval/labels/T0001_XM_20130810100251_01.mat
126 | /trainval/images/T0001_XM_20120803120253_01.jpg /trainval/labels/T0001_XM_20120803120253_01.mat
127 | /trainval/images/T0001_XM_20110810130247_02.jpg /trainval/labels/T0001_XM_20110810130247_02.mat
128 | /trainval/images/T0001_XM_20110814100248_02.jpg /trainval/labels/T0001_XM_20110814100248_02.mat
129 | /trainval/images/T0001_YM_20100806140241_02.jpg /trainval/labels/T0001_YM_20100806140241_02.mat
130 | /trainval/images/T0001_XM_20120802100252_01.jpg /trainval/labels/T0001_XM_20120802100252_01.mat
131 | /trainval/images/T0001_XM_20130806120252_01.jpg /trainval/labels/T0001_XM_20130806120252_01.mat
132 | /trainval/images/T0002_YM_20100822160221_01.jpg /trainval/labels/T0002_YM_20100822160221_01.mat
133 | /trainval/images/T0001_XM_20120805140251_01.jpg /trainval/labels/T0001_XM_20120805140251_01.mat
134 | /trainval/images/T0001_XM_20120801110252_01.jpg /trainval/labels/T0001_XM_20120801110252_01.mat
135 | /trainval/images/T0001_XM_20120806090255_01.jpg /trainval/labels/T0001_XM_20120806090255_01.mat
136 | /trainval/images/T0006_XM_20120812100307_01.jpg /trainval/labels/T0006_XM_20120812100307_01.mat
137 | /trainval/images/T0002_XM_20120804160222_01.jpg /trainval/labels/T0002_XM_20120804160222_01.mat
138 | /trainval/images/T0006_XM_20120814100307_01.jpg /trainval/labels/T0006_XM_20120814100307_01.mat
139 | /trainval/images/T0002_YM_20100817130219_01.jpg /trainval/labels/T0002_YM_20100817130219_01.mat
140 | /trainval/images/T0001_YM_20100806150239_02.jpg /trainval/labels/T0001_YM_20100806150239_02.mat
141 | /trainval/images/T0001_XM_20120808160255_01.jpg /trainval/labels/T0001_XM_20120808160255_01.mat
142 | /trainval/images/T0002_XM_20120805120223_01.jpg /trainval/labels/T0002_XM_20120805120223_01.mat
143 | /trainval/images/T0006_XM_20120812130306_01.jpg /trainval/labels/T0006_XM_20120812130306_01.mat
144 | /trainval/images/T0002_XM_20120805110221_01.jpg /trainval/labels/T0002_XM_20120805110221_01.mat
145 | /trainval/images/T0002_YM_20100819160218_01.jpg /trainval/labels/T0002_YM_20100819160218_01.mat
146 | /trainval/images/T0001_XM_20120806110255_01.jpg /trainval/labels/T0001_XM_20120806110255_01.mat
147 | /trainval/images/T0001_XM_20110809100243_02.jpg /trainval/labels/T0001_XM_20110809100243_02.mat
148 | /trainval/images/T0001_YM_20100805160242_02.jpg /trainval/labels/T0001_YM_20100805160242_02.mat
149 | /trainval/images/T0001_XM_20120807100255_01.jpg /trainval/labels/T0001_XM_20120807100255_01.mat
150 | /trainval/images/T0001_XM_20120808090256_01.jpg /trainval/labels/T0001_XM_20120808090256_01.mat
151 | /trainval/images/T0002_YM_20100818160221_01.jpg /trainval/labels/T0002_YM_20100818160221_01.mat
152 | /trainval/images/XAM01_YM_20150725100254_01.jpg /trainval/labels/XAM01_YM_20150725100254_01.mat
153 | /trainval/images/T0002_YM_20100821120220_01.jpg /trainval/labels/T0002_YM_20100821120220_01.mat
154 | /trainval/images/T0001_XM_20120807140256_01.jpg /trainval/labels/T0001_XM_20120807140256_01.mat
155 | /trainval/images/T0001_XM_20120804100257_01.jpg /trainval/labels/T0001_XM_20120804100257_01.mat
156 | /trainval/images/T0001_XM_20110813160245_02.jpg /trainval/labels/T0001_XM_20110813160245_02.mat
157 | /trainval/images/T0001_XM_20110809160243_02.jpg /trainval/labels/T0001_XM_20110809160243_02.mat
158 | /trainval/images/T0001_YM_20100807160237_02.jpg /trainval/labels/T0001_YM_20100807160237_02.mat
159 | /trainval/images/T0002_XM_20120808150221_01.jpg /trainval/labels/T0002_XM_20120808150221_01.mat
160 | /trainval/images/T0002_YM_20100821160221_01.jpg /trainval/labels/T0002_YM_20100821160221_01.mat
161 | /trainval/images/T0001_YM_20100805130237_02.jpg /trainval/labels/T0001_YM_20100805130237_02.mat
162 | /trainval/images/XAM01_YM_20150730100255_01.jpg /trainval/labels/XAM01_YM_20150730100255_01.mat
163 | /trainval/images/T0001_YM_20100809140241_02.jpg /trainval/labels/T0001_YM_20100809140241_02.mat
164 | /trainval/images/T0006_XM_20120807100309_01.jpg /trainval/labels/T0006_XM_20120807100309_01.mat
165 | /trainval/images/T0001_YM_20100807110238_02.jpg /trainval/labels/T0001_YM_20100807110238_02.mat
166 | /trainval/images/T0002_XM_20120802100223_01.jpg /trainval/labels/T0002_XM_20120802100223_01.mat
167 | /trainval/images/T0006_XM_20120813160304_01.jpg /trainval/labels/T0006_XM_20120813160304_01.mat
168 | /trainval/images/T0001_XM_20120801090255_01.jpg /trainval/labels/T0001_XM_20120801090255_01.mat
169 | /trainval/images/T0001_XM_20110810160247_02.jpg /trainval/labels/T0001_XM_20110810160247_02.mat
170 | /trainval/images/T0001_XM_20110811140245_02.jpg /trainval/labels/T0001_XM_20110811140245_02.mat
171 | /trainval/images/T0001_XM_20130805130252_01.jpg /trainval/labels/T0001_XM_20130805130252_01.mat
172 | /trainval/images/T0001_XM_20130808110252_01.jpg /trainval/labels/T0001_XM_20130808110252_01.mat
173 | /trainval/images/T0001_XM_20130804080252_01.jpg /trainval/labels/T0001_XM_20130804080252_01.mat
174 | /trainval/images/T0001_XM_20120803090253_01.jpg /trainval/labels/T0001_XM_20120803090253_01.mat
175 | /trainval/images/T0001_YM_20100804110241_02.jpg /trainval/labels/T0001_YM_20100804110241_02.mat
176 | /trainval/images/XAM01_YM_20150805100255_01.jpg /trainval/labels/XAM01_YM_20150805100255_01.mat
177 | /trainval/images/T0001_XM_20120805100257_01.jpg /trainval/labels/T0001_XM_20120805100257_01.mat
178 | /trainval/images/T0001_XM_20120806150255_01.jpg /trainval/labels/T0001_XM_20120806150255_01.mat
179 | /trainval/images/T0001_XM_20110815160245_02.jpg /trainval/labels/T0001_XM_20110815160245_02.mat
180 | /trainval/images/T0001_YM_20100806110236_02.jpg /trainval/labels/T0001_YM_20100806110236_02.mat
181 | /trainval/images/T0001_XM_20120802150254_01.jpg /trainval/labels/T0001_XM_20120802150254_01.mat
182 | /trainval/images/T0001_XM_20110810100243_02.jpg /trainval/labels/T0001_XM_20110810100243_02.mat
183 | /trainval/images/T0001_XM_20120808110251_01.jpg /trainval/labels/T0001_XM_20120808110251_01.mat
184 | /trainval/images/T0001_XM_20120804160257_01.jpg /trainval/labels/T0001_XM_20120804160257_01.mat
185 | /trainval/images/T0002_XM_20120805090222_01.jpg /trainval/labels/T0002_XM_20120805090222_01.mat
186 | /trainval/images/T0002_YM_20100728120218_01.jpg /trainval/labels/T0002_YM_20100728120218_01.mat
--------------------------------------------------------------------------------
/hltrainval.py:
--------------------------------------------------------------------------------
1 | """
2 | @author: hao
3 | """
4 |
5 | import os
6 | import argparse
7 | from time import time
8 |
9 | import cv2 as cv
10 | import numpy as np
11 | from PIL import Image
12 | from matplotlib import pyplot as plt
13 | plt.switch_backend('agg')
14 | from skimage.measure import compare_psnr
15 | from skimage.measure import compare_ssim
16 | import torch.backends.cudnn as cudnn
17 |
18 | import torch
19 | import torch.nn as nn
20 | import torch.nn.functional as F
21 | from torchvision import transforms
22 | from torch.utils.data import DataLoader
23 | from torch.optim.lr_scheduler import StepLR, MultiStepLR
24 |
25 | from hlnet import *
26 | from hldataset import *
27 | from utils import *
28 |
29 | # prevent dataloader deadlock, uncomment if deadlock occurs
30 | # cv.setNumThreads(0)
31 | cudnn.enabled = True
32 |
33 | # constant
34 | IMG_SCALE = 1./255
35 | IMG_MEAN = [.3405, .4747, .2418]
36 | IMG_STD = [1, 1, 1]
37 | SCALES = [0.7, 1, 1.3]
38 | SHORTER_SIDE = 224
39 |
40 | # system-related parameters
41 | DATA_DIR = './data/maize_counting_dataset'
42 | DATASET = 'mtc'
43 | EXP = 'tasselnetv2plus_rf110_i64o8_r0125_crop256_lr-2_bs9_epoch500'
44 | DATA_LIST = './data/maize_counting_dataset/train.txt'
45 | DATA_VAL_LIST = './data/maize_counting_dataset/test.txt'
46 |
47 | RESTORE_FROM = 'model_best.pth.tar'
48 | SNAPSHOT_DIR = './snapshots'
49 | RESULT_DIR = './results'
50 |
51 | # model-related parameters
52 | INPUT_SIZE = 64
53 | OUTPUT_STRIDE = 8
54 | MODEL = 'tasselnetv2plus'
55 | RESIZE_RATIO = 0.125
56 |
57 | # training-related parameters
58 | OPTIMIZER = 'sgd' # choice in ['sgd', 'adam']
59 | BATCH_SIZE = 9
60 | CROP_SIZE = (256, 256)
61 | LEARNING_RATE = 1e-2
62 | MILESTONES = [200, 400]
63 | MOMENTUM = 0.95
64 | MULT = 1
65 | NUM_EPOCHS = 500
66 | NUM_CPU_WORKERS = 0
67 | PRINT_EVERY = 1
68 | RANDOM_SEED = 6
69 | WEIGHT_DECAY = 5e-4
70 | VAL_EVERY = 1
71 |
72 | device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
73 |
74 | # add a new entry here if creating a new data loader
75 | dataset_list = {
76 | 'mtc': MaizeTasselDataset,
77 | 'wec': WhearEarDataset,
78 | 'shc': SorghumHeadDataset,
79 | }
80 |
81 | def get_arguments():
82 | """Parse all the arguments provided from the CLI.
83 |
84 | Returns:
85 | A list of parsed arguments.
86 | """
87 | parser = argparse.ArgumentParser(description="Object Counting Framework")
88 | # constant
89 | parser.add_argument("--image-scale", type=float, default=IMG_SCALE, help="Scale factor used in normalization.")
90 | parser.add_argument("--image-mean", nargs='+', type=float, default=IMG_MEAN, help="Mean used in normalization.")
91 | parser.add_argument("--image-std", nargs='+', type=float, default=IMG_STD, help="Std used in normalization.")
92 | parser.add_argument("--scales", type=int, default=SCALES, help="Scales of crop.")
93 | parser.add_argument("--shorter-side", type=int, default=SHORTER_SIDE, help="Shorter side of the image.")
94 | # system-related parameters
95 | parser.add_argument("--data-dir", type=str, default=DATA_DIR, help="Path to the directory containing the dataset.")
96 | parser.add_argument("--dataset", type=str, default=DATASET, help="Dataset type.")
97 | parser.add_argument("--exp", type=str, default=EXP, help="Experiment path.")
98 | parser.add_argument("--data-list", type=str, default=DATA_LIST, help="Path to the file listing the images in the dataset.")
99 | parser.add_argument("--data-val-list", type=str, default=DATA_VAL_LIST, help="Path to the file listing the images in the val dataset.")
100 | parser.add_argument("--restore-from", type=str, default=RESTORE_FROM, help="Name of restored model.")
101 | parser.add_argument("--snapshot-dir", type=str, default=SNAPSHOT_DIR, help="Where to save snapshots of the model.")
102 | parser.add_argument("--result-dir", type=str, default=RESULT_DIR, help="Where to save inferred results.")
103 | parser.add_argument("--save-output", action="store_true", help="Whether to save the output.")
104 | # model-related parameters
105 | parser.add_argument("--input-size", type=int, default=INPUT_SIZE, help="the minimum input size of the model.")
106 | parser.add_argument("--output-stride", type=int, default=OUTPUT_STRIDE, help="Output stride of the model.")
107 | parser.add_argument("--resize-ratio", type=float, default=RESIZE_RATIO, help="Resizing ratio.")
108 | parser.add_argument("--model", type=str, default=MODEL, help="model to be chosen.")
109 | parser.add_argument("--use-pretrained", action="store_true", help="Whether to use pretrained model.")
110 | parser.add_argument("--freeze-bn", action="store_true", help="Whether to freeze encoder bnorm layers.")
111 | parser.add_argument("--sync-bn", action="store_true", help="Whether to apply synchronized batch normalization.")
112 | # training-related parameters
113 | parser.add_argument("--optimizer", type=str, default=OPTIMIZER, choices=['sgd', 'adam'], help="Choose optimizer.")
114 | parser.add_argument("--batch-size", type=int, default=BATCH_SIZE, help="Number of images sent to the network in one step.")
115 | parser.add_argument("--milestones", nargs='+', type=int, default=MILESTONES, help="Multistep policy.")
116 | parser.add_argument("--crop-size", nargs='+', type=int, default=CROP_SIZE, help="Size of crop.")
117 | parser.add_argument("--evaluate-only", action="store_true", help="Whether to perform evaluation.")
118 | parser.add_argument("--learning-rate", type=float, default=LEARNING_RATE, help="Base learning rate for training.")
119 | parser.add_argument("--momentum", type=float, default=MOMENTUM, help="Momentum component of the optimizer.")
120 | parser.add_argument("--weight-decay", type=float, default=WEIGHT_DECAY, help="Regularisation parameter for L2-loss.")
121 | parser.add_argument("--mult", type=float, default=MULT, help="LR multiplier for pretrained layers.")
122 | parser.add_argument("--num-epochs", type=int, default=NUM_EPOCHS, help="Number of training epochs.")
123 | parser.add_argument("--num-workers", type=int, default=NUM_CPU_WORKERS, help="Number of CPU cores used.")
124 | parser.add_argument("--print-every", type=int, default=PRINT_EVERY, help="Print information every often.")
125 | parser.add_argument("--random-seed", type=int, default=RANDOM_SEED, help="Random seed to have reproducible results.")
126 | parser.add_argument("--val-every", type=int, default=VAL_EVERY, help="How often performing validation.")
127 | return parser.parse_args()
128 |
129 | def save_checkpoint(state, snapshot_dir, filename='model_ckpt.pth.tar'):
130 | torch.save(state, '{}/{}'.format(snapshot_dir, filename))
131 |
132 | def plot_learning_curves(net, dir_to_save):
133 | # plot learning curves
134 | fig = plt.figure(figsize=(16, 9))
135 | ax1 = fig.add_subplot(1, 2, 1)
136 | ax1.plot(net.train_loss['epoch_loss'], label='train loss', color='tab:blue')
137 | ax1.legend(loc = 'upper right')
138 | ax2 = fig.add_subplot(1, 2, 2)
139 | ax2.plot(net.val_loss['epoch_loss'], label='val mae', color='tab:orange')
140 | ax2.legend(loc = 'upper right')
141 | # ax2.set_ylim((0,50))
142 | fig.savefig(os.path.join(dir_to_save, 'learning_curves.png'), bbox_inches='tight', dpi = 300)
143 | plt.close()
144 |
145 | def train(net, train_loader, criterion, optimizer, epoch, args):
146 | # switch to 'train' mode
147 | net.train()
148 |
149 | # uncomment the following line if the training images don't have the same size
150 | cudnn.benchmark = True
151 |
152 | if args.batch_size == 1:
153 | for m in net.modules():
154 | if isinstance(m, nn.BatchNorm2d):
155 | m.eval()
156 |
157 | running_loss = 0.0
158 | avg_frame_rate = 0.0
159 | in_sz = args.input_size
160 | os = args.output_stride
161 | target_filter = torch.cuda.FloatTensor(1, 1, in_sz, in_sz).fill_(1)
162 | for i, sample in enumerate(train_loader):
163 | torch.cuda.synchronize()
164 | start = time()
165 |
166 | inputs, targets = sample['image'], sample['target']
167 | inputs, targets = inputs.cuda(), targets.cuda()
168 |
169 | # zero the parameter gradients
170 | optimizer.zero_grad()
171 |
172 | # forward
173 | outputs = net(inputs, is_normalize=False)
174 | # generate targets
175 | targets = F.conv2d(targets, target_filter, stride=os)
176 | # compute loss
177 | loss = criterion(outputs, targets)
178 |
179 | # backward + optimize
180 | loss.backward()
181 | optimizer.step()
182 | # collect and print statistics
183 | running_loss += loss.item()
184 |
185 | torch.cuda.synchronize()
186 | end = time()
187 |
188 | running_frame_rate = args.batch_size * float(1 / (end - start))
189 | avg_frame_rate = (avg_frame_rate*i + running_frame_rate)/(i+1)
190 | if i % args.print_every == args.print_every-1:
191 | print('epoch: %d, train: %d/%d, '
192 | 'loss: %.5f, frame: %.2fHz/%.2fHz' % (
193 | epoch,
194 | i+1,
195 | len(train_loader),
196 | running_loss / (i+1),
197 | running_frame_rate,
198 | avg_frame_rate
199 | ))
200 | net.train_loss['epoch_loss'].append(running_loss / (i+1))
201 |
202 |
203 | def validate(net, valset, val_loader, criterion, epoch, args):
204 | # switch to 'eval' mode
205 | net.eval()
206 | cudnn.benchmark = False
207 |
208 | image_list = valset.image_list
209 |
210 | if args.save_output:
211 | epoch_result_dir = os.path.join(args.result_dir, str(epoch))
212 | if not os.path.exists(epoch_result_dir):
213 | os.makedirs(epoch_result_dir)
214 | cmap = plt.cm.get_cmap('jet')
215 |
216 | pd_counts = []
217 | gt_counts = []
218 | with torch.no_grad():
219 | avg_frame_rate = 0.0
220 | for i, sample in enumerate(val_loader):
221 | torch.cuda.synchronize()
222 | start = time()
223 |
224 | image, gtcount = sample['image'], sample['gtcount']
225 | # inference
226 | output = net(image.cuda(), is_normalize=not args.save_output)
227 | if args.save_output:
228 | output_save = output
229 | # normalization
230 | output = Normalizer.gpu_normalizer(output, image.size()[2], image.size()[3], args.input_size, args.output_stride)
231 | # postprocessing
232 | output = np.clip(output, 0, None)
233 |
234 | pdcount = output.sum()
235 | gtcount = float(gtcount.numpy())
236 |
237 | if args.save_output:
238 | _, image_name = os.path.split(image_list[i])
239 | output_save = np.clip(output_save.squeeze().cpu().numpy(), 0, None)
240 | output_save = recover_countmap(output_save, image, args.input_size, args.output_stride)
241 | output_save = output_save / (output_save.max() + 1e-12)
242 | output_save = cmap(output_save) * 255.
243 | # image composition
244 | image = valset.images[image_list[i]]
245 | nh, nw = output_save.shape[:2]
246 | image = cv2.resize(image, (nw, nh), interpolation = cv2.INTER_CUBIC)
247 | output_save = 0.5 * image + 0.5 * output_save[:, :, 0:3]
248 |
249 | dotimage = valset.dotimages[image_list[i]]
250 |
251 | fig = plt.figure()
252 | ax1 = fig.add_subplot(1, 2, 1)
253 | ax1.imshow(dotimage.astype(np.uint8))
254 | ax1.get_xaxis().set_visible(False)
255 | ax1.get_yaxis().set_visible(False)
256 | ax2 = fig.add_subplot(1, 2, 2)
257 | ax2.imshow(output_save.astype(np.uint8))
258 | ax2.get_xaxis().set_visible(False)
259 | ax2.get_yaxis().set_visible(False)
260 | fig.suptitle('manual count=%4.2f, inferred count=%4.2f'%(gtcount, pdcount), fontsize=10)
261 | if args.dataset == 'mtc':
262 | plt.tight_layout(rect=[0, 0, 1, 1.4]) # maize tassels counting
263 | elif args.dataset == 'wec':
264 | plt.tight_layout(rect=[0, 0, 1, 1.45]) # wheat ears counting
265 | elif args.dataset == 'shc':
266 | plt.tight_layout(rect=[0, 0, 0.95, 1]) # sorghum heads counting -- dataset1
267 | # plt.tight_layout(rect=[0, 0, 1.2, 1]) # sorghum heads counting -- dataset2
268 | plt.savefig(os.path.join(epoch_result_dir, image_name.replace('.jpg', '.png')), bbox_inches='tight', dpi = 300)
269 | plt.close()
270 |
271 | # compute mae and mse
272 | pd_counts.append(pdcount)
273 | gt_counts.append(gtcount)
274 | mae = compute_mae(pd_counts, gt_counts)
275 | mse = compute_mse(pd_counts, gt_counts)
276 | rmae, rmse = compute_relerr(pd_counts, gt_counts)
277 |
278 | torch.cuda.synchronize()
279 | end = time()
280 |
281 | running_frame_rate = 1 * float(1 / (end - start))
282 | avg_frame_rate = (avg_frame_rate*i + running_frame_rate)/(i+1)
283 | if i % args.print_every == args.print_every - 1:
284 | print(
285 | 'epoch: {0}, test: {1}/{2}, pre: {3:.2f}, gt:{4:.2f}, me:{5:.2f}, mae: {6:.2f}, mse: {7:.2f}, rmae: {8:.2f}%, rmse: {9:.2f}%, frame: {10:.2f}Hz/{11:.2f}Hz'
286 | .format(epoch, i+1, len(val_loader), pdcount, gtcount, pdcount-gtcount, mae, mse, rmae, rmse, running_frame_rate, avg_frame_rate)
287 | )
288 | start = time()
289 | r2 = rsquared(pd_counts, gt_counts)
290 | np.save(args.snapshot_dir+'/pd.npy', pd_counts)
291 | np.save(args.snapshot_dir+'/gt.npy', gt_counts)
292 | print('epoch: {0}, mae: {1:.2f}, mse: {2:.2f}, rmae: {3:.2f}%, rmse: {4:.2f}%, r2: {5:.4f}'.format(epoch, mae, mse, rmae, rmse, r2))
293 | # write to files
294 | with open(os.path.join(args.snapshot_dir, args.exp+'.txt'), 'a') as f:
295 | print(
296 | 'epoch: {0}, mae: {1:.2f}, mse: {2:.2f}, rmae: {3:.2f}%, rmse: {4:.2f}%, r2: {5:.4f}'.format(epoch, mae, mse, rmae, rmse, r2),
297 | file=f
298 | )
299 | with open(os.path.join(args.snapshot_dir, 'counts.txt'), 'a') as f:
300 | for pd, gt in zip(pd_counts, gt_counts):
301 | print(
302 | '{0} {1}'.format(pd, gt),
303 | file=f
304 | )
305 | # save stats
306 | net.val_loss['epoch_loss'].append(mae)
307 | net.measure['mae'].append(mae)
308 | net.measure['mse'].append(mse)
309 | net.measure['rmae'].append(rmae)
310 | net.measure['rmse'].append(rmse)
311 | net.measure['r2'].append(r2)
312 |
313 | def main():
314 | args = get_arguments()
315 |
316 | # args.evaluate_only = True
317 | # args.save_output = True
318 |
319 | args.image_mean = np.array(args.image_mean).reshape((1, 1, 3))
320 | args.image_std = np.array(args.image_std).reshape((1, 1, 3))
321 |
322 | args.crop_size = tuple(args.crop_size) if len(args.crop_size) > 1 else args.crop_size
323 |
324 | # seeding for reproducbility
325 | if torch.cuda.is_available():
326 | torch.cuda.manual_seed(args.random_seed)
327 | torch.manual_seed(args.random_seed)
328 | np.random.seed(args.random_seed)
329 |
330 | # instantiate dataset
331 | dataset = dataset_list[args.dataset]
332 |
333 | args.snapshot_dir = os.path.join(args.snapshot_dir, args.dataset.lower(), args.exp)
334 | if not os.path.exists(args.snapshot_dir):
335 | os.makedirs(args.snapshot_dir)
336 |
337 | args.result_dir = os.path.join(args.result_dir, args.dataset.lower(), args.exp)
338 | if not os.path.exists(args.result_dir):
339 | os.makedirs(args.result_dir)
340 |
341 | args.restore_from = os.path.join(args.snapshot_dir, args.restore_from)
342 |
343 | arguments = vars(args)
344 | for item in arguments:
345 | print(item, ':\t' , arguments[item])
346 |
347 | # instantiate network
348 | net = CountingModels(
349 | arc=args.model,
350 | input_size=args.input_size,
351 | output_stride=args.output_stride
352 | )
353 |
354 | net = nn.DataParallel(net)
355 | net.cuda()
356 |
357 | # filter parameters
358 | learning_params = [p[1] for p in net.named_parameters()]
359 | pretrained_params = []
360 |
361 | # define loss function and optimizer
362 | criterion = nn.L1Loss(reduction='mean').cuda()
363 |
364 | if args.optimizer == 'sgd':
365 | optimizer = torch.optim.SGD(
366 | [
367 | {'params': learning_params},
368 | {'params': pretrained_params, 'lr': args.learning_rate / args.mult},
369 | ],
370 | lr=args.learning_rate,
371 | momentum=args.momentum,
372 | weight_decay=args.weight_decay
373 | )
374 | elif args.optimizer == 'adam':
375 | optimizer = torch.optim.Adam(
376 | [
377 | {'params': learning_params},
378 | {'params': pretrained_params, 'lr': args.learning_rate / args.mult},
379 | ],
380 | lr=args.learning_rate
381 | )
382 | else:
383 | raise NotImplementedError
384 |
385 | # restore parameters
386 | start_epoch = 0
387 | net.train_loss = {
388 | 'running_loss': [],
389 | 'epoch_loss': []
390 | }
391 | net.val_loss = {
392 | 'running_loss': [],
393 | 'epoch_loss': []
394 | }
395 | net.measure = {
396 | 'mae': [],
397 | 'mse': [],
398 | 'rmae': [],
399 | 'rmse': [],
400 | 'r2': []
401 | }
402 | if args.restore_from is not None:
403 | if os.path.isfile(args.restore_from):
404 | checkpoint = torch.load(args.restore_from)
405 | net.load_state_dict(checkpoint['state_dict'])
406 | if 'epoch' in checkpoint:
407 | start_epoch = checkpoint['epoch']
408 | if 'optimizer' in checkpoint:
409 | optimizer.load_state_dict(checkpoint['optimizer'])
410 | if 'train_loss' in checkpoint:
411 | net.train_loss = checkpoint['train_loss']
412 | if 'val_loss' in checkpoint:
413 | net.val_loss = checkpoint['val_loss']
414 | if 'measure' in checkpoint:
415 | net.measure['mae'] = checkpoint['measure']['mae'] if 'mae' in checkpoint['measure'] else []
416 | net.measure['mse'] = checkpoint['measure']['mse'] if 'mse' in checkpoint['measure'] else []
417 | net.measure['rmae'] = checkpoint['measure']['rmae'] if 'rmae' in checkpoint['measure'] else []
418 | net.measure['rmse'] = checkpoint['measure']['rmse'] if 'rmse' in checkpoint['measure'] else []
419 | net.measure['r2'] = checkpoint['measure']['r2'] if 'r2' in checkpoint['measure'] else []
420 | print("==> load checkpoint '{}' (epoch {})"
421 | .format(args.restore_from, start_epoch))
422 | else:
423 | with open(os.path.join(args.snapshot_dir, args.exp+'.txt'), 'a') as f:
424 | for item in arguments:
425 | print(item, ':\t' , arguments[item], file=f)
426 | print("==> no checkpoint found at '{}'".format(args.restore_from))
427 |
428 | # define transform
429 | transform_train = [
430 | RandomCrop(args.crop_size),
431 | RandomFlip(),
432 | Normalize(
433 | args.image_scale,
434 | args.image_mean,
435 | args.image_std
436 | ),
437 | ToTensor(),
438 | ZeroPadding(args.output_stride)
439 | ]
440 | transform_val = [
441 | Normalize(
442 | args.image_scale,
443 | args.image_mean,
444 | args.image_std
445 | ),
446 | ToTensor(),
447 | ZeroPadding(args.output_stride)
448 | ]
449 | composed_transform_train = transforms.Compose(transform_train)
450 | composed_transform_val = transforms.Compose(transform_val)
451 |
452 | # define dataset loader
453 | trainset = dataset(
454 | data_dir=args.data_dir,
455 | data_list=args.data_list,
456 | ratio=args.resize_ratio,
457 | train=True,
458 | transform=composed_transform_train
459 | )
460 | train_loader = DataLoader(
461 | trainset,
462 | batch_size=args.batch_size,
463 | shuffle=True,
464 | num_workers=args.num_workers,
465 | pin_memory=True,
466 | drop_last=True
467 | )
468 | valset = dataset(
469 | data_dir=args.data_dir,
470 | data_list=args.data_val_list,
471 | ratio=args.resize_ratio,
472 | train=False,
473 | transform=composed_transform_val
474 | )
475 | val_loader = DataLoader(
476 | valset,
477 | batch_size=1,
478 | shuffle=False,
479 | num_workers=args.num_workers,
480 | pin_memory=True
481 | )
482 |
483 | print('alchemy start...')
484 | if args.evaluate_only:
485 | validate(net, valset, val_loader, criterion, start_epoch, args)
486 | return
487 |
488 | best_mae = 1000000.0
489 | resume_epoch = -1 if start_epoch == 0 else start_epoch
490 | scheduler = MultiStepLR(optimizer, milestones=args.milestones, gamma=0.1, last_epoch=resume_epoch)
491 | for epoch in range(start_epoch, args.num_epochs):
492 | # train
493 | train(net, train_loader, criterion, optimizer, epoch+1, args)
494 | if epoch % args.val_every == args.val_every - 1:
495 | # val
496 | validate(net, valset, val_loader, criterion, epoch+1, args)
497 | # save_checkpoint
498 | state = {
499 | 'state_dict': net.state_dict(),
500 | 'optimizer': optimizer.state_dict(),
501 | 'epoch': epoch+1,
502 | 'train_loss': net.train_loss,
503 | 'val_loss': net.val_loss,
504 | 'measure': net.measure
505 | }
506 | save_checkpoint(state, args.snapshot_dir, filename='model_ckpt.pth.tar')
507 | if net.measure['mae'][-1] <= best_mae:
508 | save_checkpoint(state, args.snapshot_dir, filename='model_best.pth.tar')
509 | best_mae = net.measure['mae'][-1]
510 | best_mse = net.measure['mse'][-1]
511 | best_rmae = net.measure['rmae'][-1]
512 | best_rmse = net.measure['rmse'][-1]
513 | best_r2 = net.measure['r2'][-1]
514 | print(args.exp+' epoch {} finished!'.format(epoch+1))
515 | print('best mae: {0:.2f}, best mse: {1:.2f}, best_rmae: {2:.2f}, best_rmse: {3:.2f}, best_r2: {4:.4f}'
516 | .format(best_mae, best_mse, best_rmae, best_rmse, best_r2))
517 | plot_learning_curves(net, args.snapshot_dir)
518 | scheduler.step()
519 |
520 | print('Experiments with '+args.exp+' done!')
521 | with open(os.path.join(args.snapshot_dir, args.exp+'.txt'), 'a') as f:
522 | print(
523 | 'best mae: {0:.2f}, best mse: {1:.2f}, best_rmae: {2:.2f}, best_rmse: {3:.2f}, best_r2: {4:.4f}'
524 | .format(best_mae, best_mse, best_rmae, best_rmse, best_r2),
525 | file=f
526 | )
527 | print(
528 | 'overall best mae: {0:.2f}, overall best mse: {1:.2f}, overall best_rmae: {2:.2f}, overall best_rmse: {3:.2f}, overall best_r2: {4:.4f}'
529 | .format(min(net.measure['mae']), min(net.measure['mse']), min(net.measure['rmae']), min(net.measure['rmse']), max(net.measure['r2'])),
530 | file=f
531 | )
532 |
533 | if __name__ == "__main__":
534 | main()
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------