コード例 #1
0
	def callback(self,data):
		with session.as_default():
			assert tf.get_default_session() is session
			cv_image = self.bridge.imgmsg_to_cv2(data, desired_encoding="mono8")
			np_image = (cv_image.astype(np.float32) - pixel_depth / 2) / pixel_depth
			self.input_image = np_image.reshape((1,image_size,image_size,num_channels)).astype(np.float32)
			prediction = tf.nn.softmax(model(self.input_image))
	  		pre_dict = dict(zip(list(range(num_labels)),prediction.eval()[0]))
	        sorted_pre_dict = sorted(pre_dict.items(), key=operator.itemgetter(1))
	        name1 = value2name[sorted_pre_dict[-1][0]]
	        value1 = sorted_pre_dict[-1][1]
	        name2 = value2name[sorted_pre_dict[-2][0]]
	        value2 = sorted_pre_dict[-2][1]
	        pre = PredictionMSG()
	        pre.name1, pre.value1, pre.name2, pre.value2 = name1, value1, name2, value2
	        self.pub1.publish(pre)
	        sys.stdout.write(".")
	        sys.stdout.flush()
コード例 #2
0
 def valuate(self, data):
     config = tf.ConfigProto()
     # config.log_device_placement = True
     with tf.Session(graph=graph, config=config) as session:
         saver.restore(session, "model.ckpt")
         while self.got_image:
             self.got_image = False
             prediction = tf.nn.softmax(model(self.input_image))
             pre_dict = dict(zip(list(range(num_labels)), prediction.eval()[0]))
         sorted_pre_dict = sorted(pre_dict.items(), key=operator.itemgetter(1))
         name1 = value2name[sorted_pre_dict[-1][0]]
         value1 = sorted_pre_dict[-1][1]
         name2 = value2name[sorted_pre_dict[-2][0]]
         value2 = sorted_pre_dict[-2][1]
         pre = PredictionMSG()
         pre.name1, pre.value1, pre.name2, pre.value2 = name1, value1, name2, value2
         self.pub1.publish(pre)
         sys.stdout.write(".")
         sys.stdout.flush()
         """cv_image = self.bridge.imgmsg_to_cv2(data, desired_encoding="mono8")
コード例 #3
0
 def valuate(self, data):
     config = tf.ConfigProto()
     #config.log_device_placement = True
     with tf.Session(graph=graph, config=config) as session:
         saver.restore(session, "new_model.ckpt")
         while self.got_image:
             self.got_image = False
             prediction = tf.nn.softmax(model(self.input_image))
             pre_dict = dict(
                 zip(list(range(num_labels)),
                     prediction.eval()[0]))
         sorted_pre_dict = sorted(pre_dict.items(),
                                  key=operator.itemgetter(1))
         name1 = value2name[sorted_pre_dict[-1][0]]
         value1 = sorted_pre_dict[-1][1]
         name2 = value2name[sorted_pre_dict[-2][0]]
         value2 = sorted_pre_dict[-2][1]
         pre = PredictionMSG()
         pre.name1, pre.value1, pre.name2, pre.value2 = name1, value1, name2, value2
         self.pub1.publish(pre)
         sys.stdout.write(".")
         sys.stdout.flush()
         '''cv_image = self.bridge.imgmsg_to_cv2(data, desired_encoding="mono8")