Skip to content

Commit

Permalink
fix rescale bug
Browse files Browse the repository at this point in the history
  • Loading branch information
conan7882 committed Jan 14, 2019
1 parent 3a52e6d commit 25eab28
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 415 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
- Result images are saved in `save_path` setting in `configs/pretrain_coco_path.cfg`.

### Sample results
<img src='docs/figs/pretrained/im0.png' height='350px'>
<img src='docs/figs/pretrained/im0.png' height='300px'>
<!--<img src='docs/figs/pretrained/im1.png' height='350px'>-->
<img src='docs/figs/pretrained/im2.png' height='350px'>
<img src='docs/figs/pretrained/im3.png' height='400px'>
<img src='docs/figs/pretrained/im4.png' height='400px'>
<img src='docs/figs/pretrained/im2.png' height='300px'>
<img src='docs/figs/pretrained/im3.png' height='300px'>
<img src='docs/figs/pretrained/im4.png' height='300px'>

## Train on [VOC2012](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/) dataset (20 classes)
### Prepare dataset and pre-trained feature extractor
Expand Down Expand Up @@ -125,7 +125,7 @@
- Validation image are all rescaled to 416 * 416 without augmentation for validation.
- The learning rate schedule needs to be further tuned, but the current setting is: 0.1 (1-50 epochs), 0.01 (51-100 epochs) and 0.001 (101-150 epochs).
- Tensorboard summary includes losses and sample predictions for both training set (every 100 steps) and validation set (every epoch) are saved in `save_path` in `configs/config_path.cfg`. Note that non-maximum suppression does not used in sample predictions and only top 20 predicted bounding boxes based on class score are shown. You can see how the model is doing during training:
<img src='docs/figs/train/tensorboard.png' height='350px'>
<img src='docs/figs/train/tensorboard.png' height='400px'>

### Sample results
- Prediction after 150 epochs. Performance evaluation will be added soon.
Expand Down
2 changes: 1 addition & 1 deletion experiment/configs/config_path.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[path]
coco_pretrained_npy = /home/qge2/workspace/data/pretrain/yolo/yolov3.npy
save_path = /home/qge2/workspace/data/out/yolo/yolo_15/
save_path = /home/qge2/workspace/data/out/yolo/yolo_16/
test_image_path = ../data/yolo/
test_image_name = .jpg
yolo_feat_pretraind_npy = /home/qge2/workspace/data/pretrain/yolo/yolov3_feat.npy
Expand Down
14 changes: 9 additions & 5 deletions experiment/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ def predict():
label_dict = loader.load_imagenet1k_label_darknet()
# create a Dataflow object for test images
image_data = loader.read_image(
im_name=FLAGS.im_name, n_channel=3,
data_dir=FLAGS.data_dir, batch_size=1,
rescale=FLAGS.rescale)
im_name=FLAGS.im_name,
n_channel=3,
batch_size=1,
rescale=FLAGS.rescale,
data_dir=FLAGS.data_dir, )

# create test model
test_model = DarkNet53(
n_channel=3,n_class=1000,
pre_trained_path=FLAGS.pretrained_path, trainable=False)
n_channel=3,
n_class=1000,
pre_trained_path=FLAGS.pretrained_path,
trainable=False)
test_model.create_valid_model()

with tf.Session() as sess:
Expand Down
12 changes: 8 additions & 4 deletions experiment/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def load_VOC(rescale_shape_list,
# im_dir = '/home/qge2/workspace/data/dataset/VOCdevkit/VOC2012/JPEGImages/'
# xml_dir = '/home/qge2/workspace/data/dataset/VOCdevkit/VOC2012/Annotations/'
# elif platform.node() == 'aros04':
# im_dir = 'E:/Dataset/VOCdevkit/VOC2007/JPEGImages/'
# xml_dir = 'E:/Dataset/VOCdevkit/VOC2007/Annotations/'
# im_dir = 'E:/Dataset/VOCdevkit/test/JPEGImages/'
# xml_dir = 'E:/Dataset/VOCdevkit/test/Annotations/'
# else:
# im_dir = '/Users/gq/workspace/Dataset/VOCdevkit/VOC2007/JPEGImages/'
# xml_dir = '/Users/gq/workspace/Dataset/VOCdevkit/VOC2007/Annotations/'
# im_dir = '/Users/gq/workspace/Dataset/VOCdevkit/test/JPEGImages/'
# xml_dir = '/Users/gq/workspace/Dataset/VOCdevkit/test/Annotations/'

class_name_dict, class_id_dict = get_class_dict_from_xml(xml_dir)

Expand All @@ -94,6 +94,7 @@ def normalize_im(im, *args):
im = im / 255.
return np.clip(im, 0., 1.)

# Load entire dataset
voc_data = VOC(
class_dict=class_name_dict,
image_dir=im_dir,
Expand All @@ -105,11 +106,13 @@ def normalize_im(im, *args):
)
voc_data.setup(epoch_val=0, batch_size=1)

# divide dataset into training and validation set
train_data, valid_date = dfoper.divide_dataflow(voc_data, divide_list=[train_percentage, 1 - train_percentage], shuffle=True)

if n_class is None:
n_class = len(class_name_dict)

# create training set Generator
train_data_generator = generator.Generator(
dataflow=train_data,
n_channle=3,
Expand All @@ -124,6 +127,7 @@ def normalize_im(im, *args):
max_num_bbox_per_im=max_num_bbox_per_im)
train_data_generator.reset_im_scale(scale=416)

# create validation set Generator
valid_data_generator = generator.Generator(
dataflow=valid_date,
n_channle=3,
Expand Down
9 changes: 4 additions & 5 deletions experiment/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
sys.path.append('../')
import loader
import configs.parsecfg as parscfg
import src.bbox.bboxgt as bboxgt

import src.utils.image as image
import src.dataflow.augmentation as augment
Expand Down Expand Up @@ -160,7 +159,6 @@ def test_input():
num_parallel_preprocess=2,
h_flip=True, crop=True, color=True, affine=True,
max_num_bbox_per_im=45)

print(valid_data_generator.batch_data)

with tf.Session() as sess:
Expand All @@ -169,18 +167,19 @@ def test_input():

for epoch in range(10):
print('epoch: {}'.format(epoch))
train_data_generator.init_iterator(sess)
train_data_generator.init_iterator(sess, reset_scale=True)
while True:
try:
# train_data_generator.init_iterator(sess, reset_scale=True)
# train_data_generator.reset_im_scale()
start_time = time.time()
t = sess.run(train_data_generator.batch_data)
print(time.time() - start_time)
print(t[0].shape)
print(t[-1].shape)
viz.draw_bounding_box(t[0][0]*255, t[-1][0], label_list=None, box_type='xyxy')
viz.draw_bounding_box(t[0][0]*255, t[2][0], label_list=None, box_type='xyxy')
except tf.errors.OutOfRangeError:
break
pre.set_output_scale(416)

# def test_divide_df():
# import src.utils.viz as viz
Expand Down
13 changes: 9 additions & 4 deletions experiment/yolov3.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,22 @@ def train():
# category_index,
# config.save_path,
# run_type='epoch')

train_data_generator.init_iterator(sess)

if i > 0 and i % 10 == 0:
train_data_generator.init_iterator(sess, reset_scale=True)
else:
train_data_generator.init_iterator(sess, reset_scale=False)

train_model.train_epoch(sess, lr, summary_writer=writer)

valid_data_generator.init_iterator(sess)
valid_model.valid_epoch(sess, summary_writer=writer)

saver.save(sess, '{}/yolov3_epoch_{}'.format(config.save_path, i))

if i > 0 and i % 10 == 0:
train_data_generator.reset_im_scale()
# if i > 0 and i % 10 == 0:
# train_data_generator.reset_im_scale()

writer.close()

def detect():
Expand Down
Loading

0 comments on commit 25eab28

Please sign in to comment.