Python 输出标签Y列形状keras tensorflow 1.4

Python 输出标签Y列形状keras tensorflow 1.4,python,tensorflow,keras,Python,Tensorflow,Keras,我正在svhn数据库上运行VGG16图像分类网络。 我正在将图像保存到形状(无,64,64,3)和形状标签(无,10)。标签是大小为10的一维数组 下面是我代码的一部分 import pandas as pd import numpy as np import cv2 import tensorflow as tf import os import scipy from skimage import data, io, filters import scipy.io as sio from ut

我正在svhn数据库上运行VGG16图像分类网络。 我正在将图像保存到形状(无,64,64,3)和形状标签(无,10)。标签是大小为10的一维数组

下面是我代码的一部分

import pandas as pd
import numpy as np
import cv2
import tensorflow as tf
import os
import scipy
from skimage import data, io, filters
import scipy.io as sio
from utils import *
import h5py

vgg = tf.keras.applications.vgg16.VGG16 (include_top=False,
weights='imagenet',
input_tensor=None,
input_shape=(64,64,3),
pooling='avg',
classes=10)

vgg.compile(loss='categorical_crossentropy',
          optimizer='sgd',
          metrics=['accuracy'])

vgg.fit(train_data, labels_data, epochs=5, batch_size=32)
所以我得到了一个错误:

    ValueError: Error when checking target: expected block5_pool to have shape (None, 512) but got array with shape (None, 10)
我应该做什么改变

根据,当您将
include_top
设置为
False
时,您将省略3个完全连接的层,如果将其设置为
True
,则需要1000个类的
imagenet
预训练权重

因此,您需要将完全连接的层连接到vgg网络的顶部:

model = Sequential([vgg, Dense(10), Activation('softmax')])
model.compile(loss='categorical_crossentropy',
          optimizer='sgd',
          metrics=['accuracy'])

# now check the input/output shapes
print(model.input_shape)
print(model.output_shape)

什么是
weights
tensor?请发布所有必要的代码来重现您的问题。它是“imagenet”。好的,我正在通过(无,512)形状的标签,如果你能解释为什么输出不收敛到(无,10),这将是非常有帮助的。谢谢。但我在训练中的准确率仍然只有20%。你能帮忙吗?我正在将图像规格化并调整大小为64*64,然后将它们输入这个Vgg模型。我也尝试了图像量化,但没有提高准确性。也许图像净重不适合svhn问题?