def main(): if (len(sys.argv) != 2): print('Give the model path.') return drive = DriveRun(sys.argv[1]) config = Config() csv_fname = '/home/mir-alb/Ninad_Thesis/Test/Test.csv' csv_header = ['image_fname', 'steering_angle'] df = pd.read_csv(csv_fname, names=csv_header, index_col=False) num_data = len(df) text = open('/home/mir-lab/Ninad_Thesis/Test/Salient/Salient.txt', 'w+') bar = ProgressBar() image_process = ImageProcess() for i in bar(range(num_data)): image_name = df.loc[i]['image_fname'] steering = df.loc[i]['steering_angle'] image_path = '/home/mir-lab/Ninad_Thesis/Test/' + image_name + '.jpg' image = utils.load_img(image_path, target_size=(config.image_size[1], config.image_size[0])) image = image_process.process(image) prediction = drive.run(image) text.write(str(image_name) + '\t' + str(steering) + '\t' + str(prediction)) modifiers = [None, 'negate', 'small_values'] for i, modifier in enumerate(modifiers): heatmap = visualize_saliency(drive.net_model.model, layer_idx=-1, filter_indices=0, seed_input=image, grad_modifier=modifier, keepdims=True) final = overlay(image, heatmap, alpha=0.5) cv2.imwrite('/home/mir-lab/Ninad_Thesis/Test/Salient/' + image_name + '_' + str(i) + '.jpg', final)
def main(): config = Config() image_process = ImageProcess() try: if (len(sys.argv) != 3): print('Use model_path image_file_name.') return image = cv2.imread(sys.argv[2]) image = cv2.resize(image, (config.image_size[0], config.image_size[1])) image = image_process.process(image) if (len(image) == 0): print('File open error: ', sys.argv[2]) return drive_run = DriveRun(sys.argv[1]) measurments = drive_run.run(image) print(measurments) except KeyboardInterrupt: print ('\nShutdown requested. Exiting...')
def controller(image): img = ic.imgmsg_to_opencv(image) img = img[28:-34, :] img = image_process.process(img) drive_run = DriveRun(sys.argv[1]) measurments = drive_run.run(img) pub.publish(measurments) rate.sleep()
def __init__(self): rospy.init_node('BMW_controller') self.rate = rospy.Rate(30) self.ic = ImageConverter() self.image_process = ImageProcess() self.drive = DriveRun(sys.argv[1]) self.driveC = DriveRun(sys.argv[2]) rospy.Subscriber('/image_topic_2', Image, self.controller_cb) rospy.Subscriber('/usb_cam/image_raw', Image, self.recorder1) self.image = None self.image_processed = False
def __init__(self): self.ic = ImageConverter() self.image_process = ImageProcess() self.driveC = DriveRun(sys.argv[2]) rospy.Subscriber('/usb_cam/image_raw', Image, self.recorder1) self.imageC = None self.camera_processed = False
def __init__(self): rospy.init_node('controller') self.ic = ImageConverter() self.image_process = ImageProcess() self.rate = rospy.Rate(10) self.drive= DriveRun(sys.argv[1]) rospy.Subscriber('/bulldogbolt/camera_left/image_raw_left', Image, self.controller_cb) self.image = None self.image_processed = False
def __init__(self): rospy.init_node('BMW_controller_lidar') self.rate = rospy.Rate(20) self.ic = ImageConverter() self.image_process = ImageProcess() self.drive = DriveRun(sys.argv[1]) rospy.Subscriber('/image_topic_2', Image, self.controller_cb) self.image = None self.lidar_processed = False
def main(model_path, input): image_file_name = input[0] if Config.neural_net['num_inputs'] == 2: velocity = input[1] image = cv2.imread(image_file_name) image_process = ImageProcess() # show the image fig, (ax1, ax2) = plt.subplots(1, 2) ax1.imshow(image) ax1.set(title='original image') # if collected data is not cropped then crop here # otherwise do not crop. if Config.data_collection['crop'] is not True: image = image[Config.data_collection['image_crop_y1']:Config. data_collection['image_crop_y2'], Config.data_collection['image_crop_x1']:Config. data_collection['image_crop_x2']] image = cv2.resize(image, (Config.neural_net['input_image_width'], Config.neural_net['input_image_height'])) image = image_process.process(image) drive_run = DriveRun(model_path) if Config.neural_net['num_inputs'] == 2: predict = drive_run.run((image, velocity)) steering_angle = predict[0][0] throttle = predict[0][1] fig.suptitle('pred-steering:{} pred-throttle:{}'.format( steering_angle, throttle)) else: predict = drive_run.run((image, )) steering_angle = predict[0][0] fig.suptitle('pred_steering:{}'.format(steering_angle)) ax2.imshow(image) ax2.set(title='resize and processed') plt.show()
def __init__(self): rospy.init_node('controller') self.ic = ImageConverter() self.image_process = ImageProcess() self.rate = rospy.Rate(30) self.drive = DriveRun(sys.argv[1]) rospy.Subscriber('/bolt/front_camera/image_raw', Image, self.controller_cb) self.image = None self.image_processed = False self.config = Config()
def __init__(self, weight_file_name): rospy.init_node('run_neural') self.ic = ImageConverter() self.image_process = ImageProcess() self.rate = rospy.Rate(30) self.drive = DriveRun(weight_file_name) rospy.Subscriber(Config.data_collection['camera_image_topic'], Image, self._controller_cb) self.image = None self.image_processed = False #self.config = Config() self.braking = False
def run(self): global prediction # define size of bounding box and pass it to LocalScreenGrab class bbox = (65,270,705,410) local_grab = LocalScreenGrab(bbox) # load model drive_run = DriveRun(sys.argv[1]) print('model loaded...') try: while True: arr_screenshot = (local_grab.grab()).reshape(140, 640, 3) game_image = cv2.resize(arr_screenshot, (0,0), fx = self.config.image_size[0] / 640, fy = self.config.image_size[1] / 140) prediction = (float(drive_run.run(game_image))) / self.config.input_scale #print(prediction) # if (abs(prediction) < 0.05) is True: # prediction = 0 #print ('time_taken to get prediction {}'.format(time.time()-last_time)) except KeyboardInterrupt: print('\nShutdown requested. Exiting...')
def taker(data): joy_pub = rospy.Publisher('/joy', Joy, queue_size=10) joy_data = Joy() img = ic.imgmsg_to_opencv(data) config = Config() image_process = ImageProcess() IImage = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) IImage = cv2.resize(IImage, (config.image_size[0], config.image_size[1])) IImage = image_process.process(IImage) #cv2.imwrite('balu.jpg', IImage) #drive_run = DriveRun(sys.agrv[1]) drive_run = DriveRun( '/home/mir-lab/Desktop/Balu_Autodrive/2018-06-14-15-16-03') prediction = drive_run.run(IImage) #print(prediction) #print(np.shape(prediction)) #print(type(prediction)) if (prediction[0][0] > 0.3): #print("1") prediction[0][0] = 1 elif (prediction[0][0] < -0.3): #print("2") prediction[0][0] = -1 else: #print("3") prediction[0][0] = 0 #new_pred = prediction.astype(np.float) #new_predd = np.asscalar(np.array([prediction])) #print(type(new_predd)) #print(np.shape(new_predd)) #new_predd = joy_data.axes.append(0) #0.25 = joy_data.axes.append(3) #print(new_predd) #print(prediction[0][0]) joy_data.axes = [prediction[0][0], 0, 0, 0.05, 0, 0] joy_pub.publish(joy_data)
def main(): try: if(len(sys.argv) != 2): print('Use model_name') return drive= DriveRun(sys.argv[1]) while not rospy.is_shutdown(): try: predict_from_camera(drive) except KeyboardInterrupt: break print("out") except KeyboardInterrupt: print('\nShutdown requested. Exiting...')
def main(): try: if (len(sys.argv) != 2): print('Use model_name') return else: # load model drive = DriveRun( '/home/mir-lab/Desktop/Balu_Autodrive/2018-06-14-15-16-03') print('model loaded...') taker(data) except KeyboardInterrupt: print('\nShutdown requested. Exiting...')
def main(model_path, image_file_path): image_process = ImageProcess() image = cv2.imread(image_file_path) # if collected data is not cropped then crop here # otherwise do not crop. if Config.data_collection['crop'] is not True: image = image[Config.data_collection['image_crop_y1']:Config. data_collection['image_crop_y2'], Config.data_collection['image_crop_x1']:Config. data_collection['image_crop_x2']] image = cv2.resize(image, (Config.neural_net['input_image_width'], Config.neural_net['input_image_height'])) image = image_process.process(image) drive_run = DriveRun(model_path) measurement = drive_run.run((image, )) """ grad modifier doesn't work somehow fig, axs = plt.subplots(1, 3) fig.suptitle('Saliency Visualization' + str(measurement)) titles = ['left steering', 'right steering', 'maintain steering'] modifiers = [None, 'negate', 'small_values'] for i, modifier in enumerate(modifiers): layer_idx = utils.find_layer_idx(drive_run.net_model.model, 'conv2d_last') heatmap = visualize_cam(drive_run.net_model.model, layer_idx, filter_indices=None, seed_input=image, backprop_modifier='guided', grad_modifier=modifier) axs[i].set(title = titles[i]) axs[i].imshow(image) axs[i].imshow(heatmap, cmap='jet', alpha=0.3) """ plt.figure() #plt.title('Saliency Visualization' + str(measurement)) plt.title('Steering Angle Prediction: ' + str(measurement[0][0])) layer_idx = utils.find_layer_idx(drive_run.net_model.model, 'conv2d_last') heatmap = visualize_cam(drive_run.net_model.model, layer_idx, filter_indices=None, seed_input=image, backprop_modifier='guided') plt.imshow(image) plt.imshow(heatmap, cmap='jet', alpha=0.5) # file name loc_slash = image_file_path.rfind('/') if loc_slash != -1: # there is '/' in the data path image_file_name = image_file_path[loc_slash + 1:] saliency_file_path = model_path + '_' + image_file_name + '_saliency.png' saliency_file_path_pdf = model_path + '_' + image_file_name + '_saliency.pdf' plt.tight_layout() # save fig plt.savefig(saliency_file_path, dpi=150) plt.savefig(saliency_file_path_pdf, dpi=150) print('Saved ' + saliency_file_path + ' & .pdf')