11# -*- coding: utf-8 -*-
22
33import sys
4+ sys .path .append ("/home/katou01/code/Faster_RCNN_tensorflow" )
5+ sys .path .append ("/home/katou01/code/Faster_RCNN_tensorflow/util" )
6+ sys .path .append ("/home/katou01/code/Faster_RCNN_tensorflow/cython_util" )
47import glob
58import cv2
69import numpy as np
710# from vgg16 import vgg16
811from input_kitti import *
9- from util import *
12+ from data_util import *
1013from parse_xml import parseXML
1114from base_vgg16 import Vgg16
1215import tensorflow as tf
1619from bool_anchors_inside_image import batch_inside_image
1720from generate_anchors import generate_anchors
1821# from utility.image.data_augmentation.flip import Flip
19- sys .path .append ("/Users/tsujiyuuki/env_python/code/my_code/Data_Augmentation" )
22+ # sys.path.append("/Users/tsujiyuuki/env_python/code/my_code/Data_Augmentation")
2023
2124"""
2225・collect dataset of cars
@@ -164,9 +167,9 @@ def rpn_loss(rpn_cls, rpn_bbox, g_bbox_regression, true_index, false_index):
164167 return total_loss , cls_loss , bbox_loss
165168
166169
167- def create_Labels_For_Loss (gt_boxes , feat_stride = 16 , feature_shape = (64 , 64 ), \
170+ def create_Labels_For_Loss (gt_boxes , feat_stride = 16 , feature_shape = (64 , 19 ), \
168171 scales = np .array ([8 , 16 , 32 ]), ratios = [0.5 , 0.8 , 1 ], \
169- image_size = (500 , 1000 )):
172+ image_size = (300 , 1000 )):
170173 """This Function is processed before network input
171174 Number of Candicate Anchors is Feature Map width * heights
172175 Number of Predicted Anchors is Batch Num * Feature Map Width * Heights * 9
@@ -180,8 +183,8 @@ def create_Labels_For_Loss(gt_boxes, feat_stride=16, feature_shape=(64, 64), \
180183candicate_anchors, true_index, false_index = create_Labels_For_Loss(gt_boxes)
181184candicate_anchors[true_index==1][97]
182185 """
183- # import time
184- # func_start = time.time()
186+ import time
187+ func_start = time .time ()
185188 width = feature_shape [0 ]
186189 height = feature_shape [1 ]
187190 batch_size = gt_boxes .shape [0 ]
@@ -201,25 +204,35 @@ def create_Labels_For_Loss(gt_boxes, feat_stride=16, feature_shape=(64, 64), \
201204 candicate_anchors = centers .reshape (batch_size , K , 1 , 4 ) + anchors # [Batch, K, A, 4]
202205
203206 # shape is [B, K, A]
204- is_inside = batch_inside_image (candicate_anchors , image_size [0 ], image_size [1 ])
207+ is_inside = batch_inside_image (candicate_anchors , image_size [1 ], image_size [0 ])
205208
206209 # candicate_anchors: Shape is [Batch, K, A, 4]
207210 # gt_boxes: Shape is [Batch, G, 4]
208211 # true_index: Shape is [Batch, K, A]
209212 # false_index: Shape is [Batch, K, A]
213+ # print gt_boxes.shape
214+ # print gt_boxes
215+ # print np.array(gt_boxes,dtype=np.float64).dtype
216+ # print gt_boxes.dtype
217+ print gt_boxes [0 ]
218+ # box_area = (
219+ # (gt_boxes[b, g, 2] - gt_boxes[b, g, 0] + 1) *
220+ # (gt_boxes[b, g, 3] - gt_boxes[b, g, 1] + 1)
221+ # )
210222 candicate_anchors , true_index , false_index = bbox_overlaps (
211223 np .ascontiguousarray (candicate_anchors , dtype = np .float ),
212224 is_inside ,
213- np . ascontiguousarray ( gt_boxes , dtype = np . float ) )
225+ gt_boxes )
214226
215227 for i in range (batch_size ):
216228 true_where = np .where (true_index [i ] == 1 )
217229 num_true = len (true_where [0 ])
218230 if num_true > 64 :
219231 select = np .random .choice (num_true , num_true - 64 , replace = False )
220232 num_true = 64
221- true_where = remove_extraboxes (true_where [0 ], true_where [1 ], select )
222- true_index [i , true_where ] = 0
233+ batch = np .ones ((select .shape [0 ]), dtype = np .int ) * i
234+ true_where = remove_extraboxes (true_where [0 ], true_where [1 ], select , batch )
235+ true_index [true_where ] = 0
223236
224237 false_where = np .where (false_index [i ] == 1 )
225238 num_false = len (false_where [0 ])
@@ -228,7 +241,7 @@ def create_Labels_For_Loss(gt_boxes, feat_stride=16, feature_shape=(64, 64), \
228241 false_where = remove_extraboxes (false_where [0 ], false_where [1 ], select , batch )
229242 false_index [false_where ] = 0
230243
231- # print "time", time.time() - func_start
244+ print "time" , time .time () - func_start
232245 return candicate_anchors , true_index , false_index
233246
234247def create_ROIs_For_RCNN (model , g_labels , feat_stride = 16 ):
@@ -291,11 +304,24 @@ def train_rpn(batch_size, image_dir, label_dir, epoch=101, label_type="txt", lr=
291304
292305 image_dir = "/home/katou01/download/training/image_2/*.png"
293306 label_dir = "/home/katou01/download/training/label_2/*.txt"
307+ import time
308+ start = time .time ()
294309 images , labels = get_ALL_Image (image_dir , label_dir )
295- create_Labels_For_Loss (gt_boxes , feat_stride = 16 , feature_shape = (64 , 64 ), \
296- scales = np .array ([8 , 16 , 32 ]), ratios = [0.5 , 0.8 , 1 ], \
297- image_size = (500 , 1000 )):
298- print images .shape , labels .shape
310+ print "labels"
311+ print labels .shape
312+ print "images"
313+ print images .shape
314+ candicate_anchors , true_index , false_index = create_Labels_For_Loss (labels , feat_stride = 16 , feature_shape = (64 , 19 ), \
315+ scales = np .array ([1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 32 ]), ratios = [0.1 , 0.2 , 0.3 , 0.5 , 0.8 , 1 , 1.2 ], \
316+ image_size = (302 , 1000 ))
317+ print time .time () - start
318+ print images [0 ].shape , labels .shape
319+
320+ print true_index [true_index == 1 ].shape
321+ print false_index [false_index == 1 ].shape
322+
323+ print true_index [0 , true_index [0 ]== 1 ].shape
324+ print false_index [false_index == 1 ].shape
299325 #
300326 # image = im.open("./test_images/test1.jpg")
301327 # image = np.array(image, dtype=np.float32)
0 commit comments