def regression_convert_to_box(out, th=0.17, class_num_case=6): # interpolate the vector out from the neural network, generate the boxes #boxes = yolo_net_out_to_car_boxes(out[0], threshold = 0.17) #th = 0.17 #th = 0.17 boxes = yolo_net_out_to_car_boxes(out[0], threshold=th, class_num=class_num_case) return boxes
def frame_func(image): crop = image[300:650, 500:, :] resized = cv2.resize(crop, (448, 448)) batch = np.array([resized[:, :, 0], resized[:, :, 1], resized[:, :, 2]]) batch = 2 * (batch / 255.) - 1 batch = np.expand_dims(batch, axis=0) out = model.predict(batch) boxes = yolo_net_out_to_car_boxes(out[0], threshold=0.17) return draw_box(boxes, image, [[500, 1280], [300, 650]])
def frame_func(self, image): crop = image resized = cv2.resize(crop,(448,448)) batch = np.array([resized[:,:,0],resized[:,:,1],resized[:,:,2]]) batch = 2*(batch/255.) - 1 batch = np.expand_dims(batch, axis=0) out = self.model.predict(batch) boxes = yolo_net_out_to_car_boxes(out[0], threshold = 0.17) return draw_box(boxes,image,[[0, image.shape[1]], [0, image.shape[0]]])
def predict(self,imagePath, threshold=0.17): image = plt.imread(imagePath) image_crop = image resized = cv2.resize(image_crop,(448,448)) batch = np.transpose(resized,(2,0,1)) batch = 2*(batch/255.) - 1 temp = 2*(resized/255.) - 1 batch = np.expand_dims(batch, axis=0) out = self.model.predict(batch) boxes = yolo_net_out_to_car_boxes(out[0], threshold = 0.17) return boxes
def inference_and_visualize_batch_images_car_detection(model): # more examples images = [plt.imread(file) for file in glob.glob('./test_images/*.jpg')] batch = np.array([ np.transpose(cv2.resize(image[300:650, 500:, :], (448, 448)), (2, 0, 1)) for image in images ]) batch = 2 * (batch / 255.) - 1 out = model.predict(batch) f, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2, figsize=(11, 10)) th = 0.17 for i, ax in zip(range(len(batch)), [ax1, ax2, ax3, ax4, ax5, ax6]): #boxes = yolo_net_out_to_car_boxes(out[i], threshold = 0.17) boxes = yolo_net_out_to_car_boxes(out[i], threshold=th) print("boxes" + str(i)) print(boxes) ax.imshow(draw_box(boxes, images[i], [[500, 1280], [300, 650]])) pylab.show()
model.add(Dense(1470)) model.summary() load_weights(model, 'weights\\yolo-tiny.weights') imagePath = 'test_images\\test1.jpg' image = plt.imread(imagePath, 'rb') image_crop = image[300:650, 500:, :] resized = cv2.resize(image_crop, (448, 448)) batch = np.transpose(resized, (2, 0, 1)) batch = 2 * (batch / 255.) - 1 batch = np.expand_dims(batch, axis=0) # img_width, img_height = 448, 448 img = load_img(imagePath, False, target_size=(img_width, img_height)) x = img_to_array(img) x = np.expand_dims(x, axis=0) out = model.predict(x) print(np.argmax(out, axis=1)) # boxes = yolo_net_out_to_car_boxes(out[0], threshold=0.17) f, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6)) ax1.imshow(image) ax2.imshow(draw_box(boxes, plt.imread(imagePath), [[500, 1280], [300, 650]])) # img = cv2.imread(imagePath) # print(img.shape) # cv2.imshow('Amanda', img) # cv2.waitKey(0)
vehicle_model.add(Dense(256)) vehicle_model.add(Dense(4096)) vehicle_model.add(LeakyReLU(alpha=0.1)) vehicle_model.add(Dense(1470)) vehicle_model.summary() load_weights(vehicle_model, './yolo-tiny.weights') image = plt.imread(filename) image_crop = image[300:650, 500:, :] resized = cv2.resize(image_crop, (448, 448)) batch = np.transpose(resized, (2, 0, 1)) batch = 2 * (batch / 255.) - 1 batch = np.expand_dims(batch, axis=0) out = vehicle_model.predict(batch) boxes = yolo_net_out_to_car_boxes(out[0], threshold=0.12) #Parameter Tuning f, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6)) ax1.imshow(image) ax2.imshow(draw_box(boxes, plt.imread(filename), [[500, 1280], [300, 650]])) plt.show() def frame_function(image): crop = image[300:650, 500:, :] resized = cv2.resize(crop, (448, 448)) batch = np.array([resized[:, :, 0], resized[:, :, 1], resized[:, :, 2]]) batch = 2 * (batch / 255.) - 1 batch = np.expand_dims(batch, axis=0) out = vehicle_model.predict(batch) boxes = yolo_net_out_to_car_boxes(out[0], threshold=0.12) #Parameter Tuning
def regression_convert_to_box(out): # interpolate the vector out from the neural network, generate the boxes #boxes = yolo_net_out_to_car_boxes(out[0], threshold = 0.17) th = 0.17 boxes = yolo_net_out_to_car_boxes(out[0], threshold=th) return boxes