예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)