我有问题:
我正在尝试制造简单的自动驾驶汽车,该汽车可以平稳行驶并控制油门和刹车。
我遇到了这样的问题:
我无法将keras和当前车速连接到VGG_16模型。
已经尝试:
from keras.applications import VGG16
from keras import models
from keras import layers
from Train import *
import numpy as np
import keras
from keras.layers import concatenate
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
from keras.layers import Input, Flatten, Dense
from keras.models import Model
import numpy as np
import tensorflow as tf
import keras.backend as K
images, speed, labels = LoadGPS_SPEED() # load training data, image, car speed and label ([0, 1, 0], for example. Where [0 - left turn, 1 - throttle, 0 - right turn]
speed = speed.reshape(speed.shape[0], 1) # reshape to shape[0], 1, because speed is just a number (20, for example)
speed = K.variable(speed) # here is some magic, which i tired, because without that i got other error, lol. P.S Right after loading, images, speed and labels - are just numpy arrays
vgg_conv = VGG16(weights='imagenet', # VGG from default keras application
include_top=False)
for layer in vgg_conv.layers[0:-4]:
layer.trainable = False
input = Input(shape=(60,60,3),name = 'image_input')
output_vgg16_conv = vgg_conv(input)
conv_flat = layers.Flatten()(output_vgg16_conv)
conv_flat = concatenate([speed, conv_flat]) # trying to concatenate speed and flatten layer
conv_flat = layers.Dense(1024, activation='relu')(conv_flat)
conv_flat = layers.Dropout(0.5)(conv_flat)
conv_flat = layers.Dense(3, activation='softmax')(conv_flat) # 3 possible actions
并得到了这样的错误:
回溯(最近通话最近):文件 “ D:/Python_Projects/ProjectCars/ModelGenerate.py”,第34行,在 conv_flat =串联([speed,conv_flat])
文件“ C:\ Program Files \ Python35 \ lib \ site-packages \ keras \ layers \ merge.py“,第649行,在 级联 返回Concatenate(axis = axis,** kwargs)(输入)
文件“ C:\ Program Files \ Python35 \ lib \ site-packages \ keras \ engine \ base_layer.py“,行 431,在致电中 self.build(unpack_singleton(input_shapes))
文件“ C:\ Program 文件\ Python35 \ lib \ site-packages \ keras \ layers \ merge.py”,第362行,在 建立 '输入了形状:%s'%(input_shape))
ValueError:
Concatenate
层需要具有匹配形状的输入 除了concat轴。得到了输入形状:[(10,1),(None,512)]
请帮帮我。我只是一个初学者,不知道该如何解决:c