def run(self): while not rospy.is_shutdown(): msg = CNN_out() msg.header.stamp = rospy.Time.now() data = None while data is None: try: data = rospy.wait_for_message("camera", Image, timeout=10) except: pass self.use_network_out = True # delete in performance if self.use_network_out: print("Publishing commands!") else: print("NOT Publishing commands!") cv_image = utils.callback_img(data, self.target_size, self.crop_size, self.imgs_rootpath, self.use_network_out) outs = self.model.predict_on_batch(cv_image[None]) steer, coll = outs[0][0], outs[1][0] msg.steering_angle = steer msg.collision_prob = coll self.pub.publish(msg)
def run(self): t = time.time() while not rospy.is_shutdown(): msg = CNN_out() msg.header.stamp = rospy.Time.now() data = None rate = rospy.Rate(60) while self.rdy is False: rate.sleep() self.rdy = False if self.use_network_out: print("Publishing commands!") #else: # print("NOT Publishing commands!") cv_image = utils.callback_img(self.data, self.target_size, self.crop_size, self.imgs_rootpath, self.use_network_out) #print("###\n###\n") #print("$%6.3f, $%6.3f, $%6.3f, $%6.3f" % (cv_image[0,0,0], cv_image[0,20,0], cv_image[0,30,0], cv_image[0,50,0])) #print("###\n###\n") outs = self.model.predict_on_batch(cv_image[None]) steer, coll = outs[0][0], outs[1][0] print("{0}: got commands steer={1}, coll={2}".format( time.time() - t, outs[0][0], outs[1][0])) #toc = time.time() #if ( (toc - t) >= 1 ): # t = toc # print("1 sec mark") msg.steering_angle = steer msg.collision_prob = coll self.pub.publish(msg)
def run(self): while not rospy.is_shutdown(): msg = CNN_out() msg.header.stamp = rospy.Time.now() data = None while data is None: try: data = rospy.wait_for_message("camera", Image, timeout=10) except: pass cv_image = utils.callback_img(data, self.target_size, self.imgs_rootpath) outs = self.model.predict_on_batch(cv_image[None]) outs = outs * 48 + 48 # undo the normalization x1, y1, x2, y2, x3, y3, x4, y4 = outs[0][0], outs[0][1], outs[0][ 2], outs[0][3], outs[0][4], outs[0][5], outs[0][6], outs[0][7] # four corners msg.left_up_x = x1 msg.left_up_y = y1 msg.right_up_x = x2 msg.right_up_y = y2 msg.right_down_x = x3 msg.right_down_y = y3 msg.left_down_x = x4 msg.left_down_y = y4 # calculate the waypoints ahead and after the window self.pub.publish(msg) # publish eight numbers
def run(self): while not rospy.is_shutdown(): msg = CNN_out() msg.header.stamp = rospy.Time.now() data = None while data is None: try: data = rospy.wait_for_message( "/bebop2/camera_base/image_raw", Image, timeout=10) except: pass if self.use_network_out: print("Publishing commands!") else: print("NOT Publishing commands!") # Note that this call will save images if self.use_network_out is True (when DroNet takes over) # cv_image = utils.callback_img(data, self.target_size, self.crop_size, # self.imgs_rootpath, self.use_network_out) cv_image = utils.callback_img(data, self.target_size, self.crop_size, self.imgs_rootpath, False) outs = self.model.predict_on_batch(cv_image[None]) steer, coll = outs[0][0], outs[1][0] msg.steering_angle = steer msg.collision_prob = coll print("Steering: {}\nCollision: {}".format(steer, coll)) self.pub.publish(msg)
def run(self): while not rospy.is_shutdown(): msg = CNN_out() msg.header.stamp = rospy.Time.now() data = None while data is None: try: data = rospy.wait_for_message("camera", Image, timeout=10) except: pass if self.use_network_out: print("Publishing commands!") else: print("NOT Publishing commands!") cv_image = utils.callback_img(data, self.target_size, self.crop_size, self.imgs_rootpath, self.use_network_out) outs = self.model.predict_on_batch(cv_image[None]) if self.get_saliency_maps: img, cam_s, cam_c = utils.grad_cam(self.model, cv_image[None], self.crop_size, layer_name="add_3", scale_factor=2) cam_s_msg = utils.np2image(cam_s) cam_c_msg = utils.np2image(cam_c) img_msg = utils.np2image(img) self.gradcam_nn_pub.publish(img_msg) self.gradcam_col_pub.publish(cam_c_msg) self.gradcam_st_pub.publish(cam_s_msg) else: img = np.array(cv_image * 255, dtype=np.uint8) img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) img_msg = utils.np2image(img) self.gradcam_nn_pub.publish(img_msg) steer, coll = outs[0][0], outs[1][0] msg.steering_angle = steer * 30 msg.collision_prob = coll self.pub.publish(msg)