6 from std_msgs.msg
import String
7 from sensor_msgs.msg
import Image,CompressedImage
8 from geometry_msgs.msg
import Twist
10 from look_caresses_pkg.msg
import platform_config,platform_sensors,platform_state,platform_mics,platform_control,core_state,core_control,core_config,bridge_config,bridge_stream
12 from os
import listdir
13 from os.path
import isfile, join
14 from sklearn.metrics
import confusion_matrix
21 from miro_constants
import miro
22 from keras.models
import Sequential
23 from keras.layers
import Dense, Dropout, Activation
24 from keras.layers.recurrent
import LSTM
25 from keras.layers
import Embedding
26 from keras.preprocessing.sequence
import pad_sequences
27 from keras.utils
import np_utils
28 from datetime
import datetime
30 from keras
import metrics
31 from keras
import backend
as K
32 from keras
import regularizers
33 import tensorflow
as tf
35 from keras.models
import load_model
41 for i
in range(0, len(x)):
44 s = s + f.format(x[i])
50 def callback_platform_sensors(self, subscriber_msg):
70 touch_sensors = [0,0,0,0,0,0,0,0]
72 touch_sensors[0] = int(fmt(subscriber_msg.touch_head,
'{0:.0f}')[0])
73 touch_sensors[1] = int(fmt(subscriber_msg.touch_head,
'{0:.0f}')[3])
74 touch_sensors[2] = int(fmt(subscriber_msg.touch_head,
'{0:.0f}')[6])
75 touch_sensors[3] = int(fmt(subscriber_msg.touch_head,
'{0:.0f}')[9])
76 touch_sensors[4] = int(fmt(subscriber_msg.touch_body,
'{0:.0f}')[0])
77 touch_sensors[5] = int(fmt(subscriber_msg.touch_body,
'{0:.0f}')[3])
78 touch_sensors[6] = int(fmt(subscriber_msg.touch_body,
'{0:.0f}')[6])
79 touch_sensors[7] = int(fmt(subscriber_msg.touch_body,
'{0:.0f}')[9])
92 while not rospy.is_shutdown():
97 dataset.append(touch_sensors)
98 if len(dataset) == 105:
101 if data_flag ==
True:
103 x_dataset = np.array(pattern)
105 X_train = np.reshape(x_dataset, (1,x_dataset.shape[0], x_dataset.shape[1]))
106 XDataset = pad_sequences(X_train, maxlen=
None, dtype=
'int32',padding=
'pre', truncating=
'pre', value=0.)
108 with self.graph.as_default():
109 predict = self.model.predict(X_train)
111 for i
in range(len(predict[0])):
112 if predict[0][i] >= threshold:
116 index = np.argmax(predict)
118 gesture_str =
"CarBottomTop"
120 gesture_str =
"FixedBody"
122 gesture_str =
"PatHead"
124 gesture_str =
"FixedHead"
126 gesture_str =
"PatBody"
128 gesture_str =
"CarTopBottom"
130 gesture_str =
"No_Gesture"
132 rospy.loginfo(gesture_str)
133 self.pub.publish(gesture_str)
140 print(
"initialising...")
142 print(datetime.time(datetime.now()))
151 for arg
in sys.argv[1:]:
162 error(
"argument not recognised \"" + arg +
"\"")
168 error(
"argument \"robot\" must be specified")
175 print "topic_root", topic_root
178 self.
pub = rospy.Publisher(
'/miro/look4caresses/classifyGesture', String, queue_size=10)
188 self.
model = load_model(
'my_model_new.h5')
189 self.model._make_predict_function()
190 self.
graph = tf.get_default_graph()
192 adm = keras.optimizers.Adam(lr=0.00001, beta_1=0.9, beta_2=0.999, epsilon=
None, decay=0.0, amsgrad=
False)
193 self.model.compile(loss=
'categorical_crossentropy',optimizer=adm ,metrics=[
'accuracy'])
198 self.
rate = rospy.Rate(20)
200 if __name__ ==
"__main__":
221 rospy.init_node(
"miro_touch_control_ros_client_py", anonymous=
True)