Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In ep7 classifier.fit() raises "IndexError: invalid index to scalar variable" #3

Open
mbaytas opened this issue Jan 24, 2017 · 0 comments

Comments

@mbaytas
Copy link

mbaytas commented Jan 24, 2017

Full disclosure: I'm not using the Docker image, but working in my own environment on a Mac (10.12.2) with Python 2.7 (via Homebrew) and Tensorflow 0.12.1.

I'm going through the code for Episode 7, where I get an "IndexError: invalid index to scalar variable" on the line classifier.fit(data, labels, batch_size=100, steps=1000). Here's my code in full (exactly same as the tutorial):

import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
learn = tf.contrib.learn

mnist = learn.datasets.load_dataset('mnist')
data = mnist.train.images
labels = np.asarray(mnist.train.labels, dtype=np.int32)
test_data = mnist.test.images
test_labels = np.asarray(mnist.test.labels, dtype=np.int32)

max_examples = 10000
data = data[:max_examples]
labels = labels[max_examples]

feature_columns = learn.infer_real_valued_columns_from_input(data)
classifier = learn.LinearClassifier(feature_columns=feature_columns, n_classes=10)
classifier.fit(data, labels, batch_size=100, steps=1000)

Here's the complete error:

Traceback (most recent call last):
  File "/Users/mbaytas/Dropbox/works-code/ml-studies/google-recipes/ep7-mnist/ep7.py", line 38, in <module>
    classifier.fit(data, labels, batch_size=100, steps=1000)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/linear.py", line 446, in fit
    max_steps=max_steps)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 191, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 355, in fit
    max_steps=max_steps)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 733, in _train_model
    max_steps=max_steps)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/graph_actions.py", line 300, in _monitored_train
    _, loss = super_sess.run([train_op, loss_op], feed_fn() if feed_fn else
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/learn_io/data_feeder.py", line 407, in _feed_dict_fn
    out[i] = _access(self._y, sample)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/learn_io/data_feeder.py", line 208, in _access
    return data[iloc]
IndexError: invalid index to scalar variable.
@mbaytas mbaytas changed the title In ep7 classifier.fit() raises IndexError: invalid index to scalar variable In ep7 classifier.fit() raises "IndexError: invalid index to scalar variable" Jan 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant