【问题标题】:Error TensorFlow "Dimensions must be equal, but..."错误 TensorFlow“维度必须相等,但是......”
【发布时间】:2018-06-12 12:52:24
【问题描述】:

从 Tensorflow 开始,我尝试使用 IRIS 数据集重现估计器的基本示例,但使用我自己的数据。

from __future__ import absolute_import
from __future__ import division    
from __future__ import print_function

import os
from six.moves.urllib.request import urlopen

import tensorflow as tf

from pandas import DataFrame, read_csv
import numpy as np

TESTFILE = "test.csv"
TRAINFILE =  "train.csv"
# Load datasets
training_set = tf.contrib.learn.datasets.base.load_csv_with_header(filename=TRAINFILE, target_dtype=np.int, features_dtype=np.float32, target_column=0)

test_set = tf.contrib.learn.datasets.base.load_csv_with_header(filename=TESTFILE, target_dtype=np.int, features_dtype=np.float32, target_column=0)
# Specify that all features have real-value data
feature_columns = [tf.feature_column.numeric_column("x", shape=[4])]

# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns,
                                        hidden_units=[10, 20, 10],
                                        n_classes=3,
                                        model_dir="/tmp/Goldman_model")

# Define the training inputs
train_input_fn = tf.estimator.inputs.numpy_input_fn(
    x={"x": np.array(training_set.data)},
    y=np.array(training_set.target),
    num_epochs=None,
    shuffle=True)
# Train model.
classifier.train(input_fn=train_input_fn, steps=2000)

但是,当我尝试训练分类器时,我收到下一个错误:

File "C:\Users\***\Anaconda3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 691, in _call_cpp_shape_fn_impl
raise ValueError(err.message)


 ValueError: Dimensions must be equal, but are 160 and 128
 for 'dnn/head/sparse_softmax_cross_entropy_loss/xentropy/xentropy' 
(op: 'SparseSoftmaxCrossEntropyWithLogits') with input shapes: [160,3], [128].

而且我完全不知道下一步该做什么。

非常感谢您的回答,

JF 帕洛梅克

【问题讨论】:

    标签: python-3.x tensorflow


    【解决方案1】:

    您的标签和预测具有不同的维度(160 和 128)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-24
      • 2018-06-30
      • 1970-01-01
      • 2018-07-25
      • 2022-09-27
      • 2019-09-17
      • 1970-01-01
      • 2021-05-27
      相关资源
      最近更新 更多