pub_vel.angular.z = 0.8 elif predict_action[1] < -0.8: pub_vel.angular.z = -0.8 else: pub_vel.angular.z = predict_action[1] pub_vel.linear.x = pub_vel.linear.x*0.5 pub_vel.angular.z = pub_vel.angular.z * 0.5 pub.publish(pub_vel) #print("\r"+str(pub_vel) + " ",end="") print(str(pub_vel)) #print(predict_action) step_count += 1 x.append(step_count) y.append(pub_vel.angular.z*4) if(len(x)>150): x.pop(0) y.pop(0) plt.xlim(x[0],x[0]+150) line, = ax.plot(x, y, color='blue') plt.pause(0.01) # グラフをクリア line.remove() r.sleep()
def create(self): input = Input(shape=self.input_shape) def image_channels_slice(image, channel, before): if before: return image[:, :, :, :channel] else: return image[:, :, :, channel:] origin = Lambda(image_channels_slice, arguments={'channel': 3, 'before': True})(input) superpixel = Lambda(image_channels_slice, arguments={'channel': 3, 'before': False})(input) ##################### # First Convolution # ##################### tiramisu = Conv2D(self.n_first_filters, kernel_size=3, padding='same', input_shape=self.origin_shape, kernel_initializer=self.kernel_initializer, kernel_regularizer=self.regularizer)(origin) ##################### # Downsampling path # ##################### m = 0 skip_connections = [] atrous_rate = 1 for i in range(self.n_downsamples): if self.use_atrous[i]: atrous_rate *= 2 for j in range(self.n_layers_per_block[i]): l = self.AtrousLayer(self.growth_rate, rate=atrous_rate)(tiramisu) tiramisu = Concatenate()([tiramisu, l]) m += self.growth_rate skip_connections.append(None) tiramisu = Concatenate()([tiramisu, self.AtrousLayer(self.growth_rate, rate=atrous_rate)(tiramisu)]) else: for j in range(self.n_layers_per_block[i]): l = self.Layer(self.growth_rate)(tiramisu) tiramisu = Concatenate()([tiramisu, l]) m += self.growth_rate skip_connections.append(Conv2D(int(m / 2), kernel_size=1, kernel_initializer=self.kernel_initializer)(tiramisu)) # skip_connections.append(tiramisu) tiramisu = self.TransitionDown(m)(tiramisu) if skip_connections[0] == None: skip_connections[0] = superpixel else: skip_connections[0] = Concatenate()([skip_connections[0], superpixel]) skip_connections = skip_connections[::-1] self.use_atrous = self.use_atrous[::-1] ##################### # Bottleneck # ##################### upsample_tiramisu = [] for j in range(self.n_layers_per_block[self.n_downsamples]): l = self.Layer(self.growth_rate)(tiramisu) upsample_tiramisu.append(l) tiramisu = Concatenate()([tiramisu, l]) ####################### # Upsampling path # ####################### for i in range(self.n_downsamples): if self.use_atrous[i]: assert(skip_connections[i] == None) assert(not self.use_bilinear_interplolation[i]) else: upsample_tiramisu = Concatenate()(upsample_tiramisu) n_keep_filters = self.growth_rate * self.n_layers_per_block[self.n_downsamples + i] if self.use_bilinear_interplolation[i]: tiramisu = self.BilinearUp(2)(upsample_tiramisu, skip_connections[i]) else: tiramisu = self.TransitionUp(n_keep_filters)(upsample_tiramisu, skip_connections[i]) upsample_tiramisu = [] for j in range(self.n_layers_per_block[self.n_downsamples + i + 1]): l = self.Layer(self.growth_rate)(tiramisu) upsample_tiramisu.append(l) tiramisu = Concatenate()([tiramisu, l]) ##################### # Softmax # ##################### tiramisu = Conv2D(self.n_classes, kernel_size=1, padding='same', kernel_initializer=self.kernel_initializer, kernel_regularizer=self.regularizer)(tiramisu) tiramisu = Reshape((self.input_shape[0] * self.input_shape[1], self.n_classes))(tiramisu) tiramisu = Activation('softmax')(tiramisu) self.model = Model(inputs=input, outputs=tiramisu) self.model.summary() with open('tiramisu_fc_dense_model.json', 'w') as outfile: outfile.write(json.dumps(json.loads(self.model.to_json()), indent=3))