tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [64,28,10] vs错误

今天使用tensorflow构建网络时,出现了如下的问题

tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [64,28,10] vs[64,1]

主要原因是你的x_picture和y_label数据的维度不相同导致的
这是我原来对数据的处理

 with gzip.open(paths[0], 'rb') as lbpath:
    y_train = np.frombuffer(lbpath.read(), np.uint8, offset=8)

  with gzip.open(paths[1], 'rb') as imgpath:
    x_train = np.frombuffer(
        imgpath.read(), np.uint8, offset=16).reshape(len(y_train),28,28)

我将 y_train 处理为一个二维的数据,而x_train为一个三维的数据。

解决方法

将28*28改为784即可

 with gzip.open(paths[0], 'rb') as lbpath:
    y_train = np.frombuffer(lbpath.read(), np.uint8, offset=8)

  with gzip.open(paths[1], 'rb') as imgpath:
    x_train = np.frombuffer(
        imgpath.read(), np.uint8, offset=16).reshape(len(y_train),784)

你可能感兴趣的:(tensorflow,python,深度学习)