def generate_batch_data(vocPath, imageNameFile, batch_size, sample_number): """ Args: vocPath: the path of pascal voc data imageNameFile: the path of the file of image names batchsize: batch size, sample_number should be divided by batchsize Funcs: A data generator generates training batch indefinitely """ class_num = 20 #Read all the data once and dispatch them out as batches to save time TotalimageList = prepareBatch(0, sample_number, imageNameFile, vocPath) while 1: batches = sample_number // batch_size for i in range(batches): images = [] boxes = [] sample_index = np.random.choice(sample_number, batch_size, replace=True) #sample_index = [3] for ind in sample_index: image = TotalimageList[ind] #print image.imgPath image_array = crop_detection(image.imgPath, new_width=448, new_height=448) #image_array = np.expand_dims(image_array,axis=0) images.append(image_array) boxes.append(np.reshape(image.boxes, -1)) #return np.asarray(images),np.asarray(boxes) yield np.asarray(images), np.asarray(boxes)
def generate_batch_data(vocPath, imageNameFile, batch_size, sample_number): """ Args: vocPath: the path of pascal voc data imageNameFile: the path of the file of image names batchsize: batch size, sample_number should be divided by batchsize Funcs: A data generator generates training batch indefinitely """ class_num = 20 #Read all the data once and dispatch them out as batches to save time TotalimageList = prepareBatch(0, sample_number, imageNameFile, vocPath) while 1: batches = sample_number // batch_size for i in range(batches): images = [] boxes = [] sample_index = np.random.choice(sample_number, batch_size, replace=True) #sample_index = [3] for ind in sample_index: image = TotalimageList[ind] #print image.imgPath image_array = crop_detection(image.imgPath, new_width=448, new_height=448) #image_array = np.expand_dims(image_array,axis=0) y = [] for i in range(7): for j in range(7): box = image.boxes[i][j] ''' ############################################################ #x,y,h,w,one_hot class label vector[0....0],objectness{0,1}# ############################################################ ''' if (box.has_obj): obj = box.objs[0] y.append(obj.x) y.append(obj.y) y.append(obj.h) y.append(obj.w) labels = [0] * 20 labels[obj.class_num] = 1 y.extend(labels) y.append(1) #objectness else: y.extend([0] * 25) y = np.asarray(y) #y = np.reshape(y,[1,y.shape[0]]) images.append(image_array) boxes.append(y) #return np.asarray(images),np.asarray(boxes) yield np.asarray(images), np.asarray(boxes)
def generate_batch_data(vocPath,imageNameFile,batch_size,sample_number): """ Args: vocPath: the path of pascal voc data imageNameFile: the path of the file of image names batchsize: batch size, sample_number should be divided by batchsize Funcs: A data generator generates training batch indefinitely """ class_num = 20 #Read all the data once and dispatch them out as batches to save time TotalimageList = prepareBatch(0,sample_number,imageNameFile,vocPath) while 1: batches = sample_number // batch_size for i in range(batches): images = [] boxes = [] sample_index = np.random.choice(sample_number,batch_size,replace=True) #sample_index = [3] for ind in sample_index: image = TotalimageList[ind] #print image.imgPath image_array = crop_detection(image.imgPath,new_width=448,new_height=448) #image_array = np.expand_dims(image_array,axis=0) images.append(image_array) boxes.append(np.reshape(image.boxes,-1)) #return np.asarray(images),np.asarray(boxes) yield np.asarray(images),np.asarray(boxes)
def generate_batch_data(vocPath,imageNameFile,batch_size,sample_number): """ Args: vocPath: the path of pascal voc data imageNameFile: the path of the file of image names batchsize: batch size, sample_number should be divided by batchsize Funcs: A data generator generates training batch indefinitely """ class_num = 20 #Read all the data once and dispatch them out as batches to save time TotalimageList = prepareBatch(0,sample_number,imageNameFile,vocPath) while 1: batches = sample_number // batch_size for i in range(batches): images = [] boxes = [] sample_index = np.random.choice(sample_number,batch_size,replace=True) #sample_index = [3] for ind in sample_index: image = TotalimageList[ind] #print image.imgPath image_array = crop_detection(image.imgPath,new_width=448,new_height=448) #image_array = np.expand_dims(image_array,axis=0) y = [] for i in range(7): for j in range(7): box = image.boxes[i][j] ''' ############################################################ #x,y,h,w,one_hot class label vector[0....0],objectness{0,1}# ############################################################ ''' if(box.has_obj): obj = box.objs[0] y.append(obj.x) y.append(obj.y) y.append(obj.h) y.append(obj.w) labels = [0]*20 labels[obj.class_num] = 1 y.extend(labels) y.append(1) #objectness else: y.extend([0]*25) y = np.asarray(y) #y = np.reshape(y,[1,y.shape[0]]) images.append(image_array) boxes.append(y) #return np.asarray(images),np.asarray(boxes) yield np.asarray(images),np.asarray(boxes)
image_array = np.rollaxis(image_array, 2, 0) image_array = np.rollaxis(image_array, 2, 0) print image_array.shape scipy.misc.imsave('recovered.jpg', image_array) # center should be in (3,3) labels = [ "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor" ] out = y[0] imgPath = os.path.join(os.getcwd(), 'recovered.jpg') img = Image.open(imgPath) image_arr, img_resize = crop_detection(imgPath, 448, 448, save=True) drawable = ImageDraw.Draw(img_resize) #Draw orignal bounding boxes count = 0 for i in range(49): preds = out[i * 25:(i + 1) * 25] if (preds[24] > 0.3): count = count + 1 #print preds[0:4],preds[24] row = i / 7 col = i % 7 print row, col centerx = 64 * col + 64 * preds[0] centery = 64 * row + 64 * preds[1]
image_array = image_array[0,...,...,...] #scipy.misc.imsave('recovered.jpg', image_array) print image_array.shape image_array = (image_array + 1.0) / 2.0 * 225.0 image_array = np.rollaxis(image_array,2,0) image_array = np.rollaxis(image_array,2,0) print image_array.shape scipy.misc.imsave('recovered.jpg', image_array) # center should be in (3,3) labels = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train","tvmonitor"] out = y[0] imgPath = os.path.join(os.getcwd(),'recovered.jpg') img = Image.open(imgPath) image_arr,img_resize = crop_detection(imgPath,448,448,save=True) drawable = ImageDraw.Draw(img_resize) #Draw orignal bounding boxes count = 0 for i in range(49): preds = out[i*25:(i+1)*25] if(preds[24] > 0.3): count = count + 1 #print preds[0:4],preds[24] row = i/7 col = i%7 print row,col centerx = 64 * col + 64 * preds[0] centery = 64 * row + 64 * preds[1]