1

For start in Tensorflow, I am triying to reproduce the basic example of the estimator with the IRIS data set, but with my own data.

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)

But, when I try to train the classifier, I receive the next error:

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].

And I have absolutely no idea what to do next.

Thank you very much for the answers,

JF Palomeque

1 Answer 1

1

Your labels and predictions have different dimensions (160 and 128).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.