tensorflow2.0 单网络输出多个结果

单网络多输出,实际上就是最后一层多输出节点为2

 h1 = tf.keras.layers.Conv2D(24, 5, strides=2, padding="same",  activation='relu')(tf.keras.Input(shape=(28,28,1)))
        h1 = tf.keras.layers.MaxPool2D(2, strides=2)(h1)
        h1 = tf.keras.layers.Conv2D(32, 3, strides=2, padding="same", activation='relu')(h1)
        h1 = tf.keras.layers.MaxPool2D(2, strides=2)(h1)
        h1 = tf.keras.layers.Conv2D(64, 3, strides=2, padding="same",  activation='relu')(h1)
        h1 = tf.keras.layers.MaxPool2D(2)(h1)
        # h1 = tf.keras.layers.AveragePooling2D(2, strides=2)(h1)
        h1 = tf.keras.layers.Flatten()(h1)
        h1 = tf.keras.layers.Dense(128, activation='tanh')(h1)
        h1 = tf.keras.layers.Dropout(0.1)(h1)
        h1 = tf.keras.layers.Dense(64, activation='tanh')(h1)
        h1 = tf.keras.layers.Dropout(0.1)(h1)
        h1 = tf.keras.layers.Dense(2, activation='tanh')(h1)
#建立模型
_input = tf.keras.Input(shape=(28,28,1))
_model = tf.keras.Model(_input, h1)

#编译模型
model.compile(optimizer=tf.keras.optimizers.Adam(lr=0.001),
                      loss='mean_squared_error',
                      # loss_weights=lossWeights,
                      metrics=['accuracy']
                      )
#训练模型
# angle / speed.shape = [2323]  由于输出是两个节点,输入也需要是两个节点
y_train1 = y1.append(np.array([angle, speed]))
model.fit(x_train, y_train1, epochs=5)
        model.save(save_name)   

# 预测并输出结果
result = model.predict(img)
            print("result:", result)
            #when get predict data sendit at here:
            order_data = {'angle': str(result[0][0]), 'throttle': str(result[0][1])}                   

你可能感兴趣的:(AI,人工智能,#,tensorflow)