dorien
dorien

Reputation: 5407

Reader doesn't seem to be installed in TensorFlow

I have installed TensorFlow through pip for python 2.7.

I am trying to run some example RNN models, one of which requires the import of reader.

from tensorflow.models.rnn.ptb import reader

-> I get a no module reader found. 

After reading a bit, I tried a popular suggestions:

import reader

-> no module reader found. 

I ran:

import inspect
>>> print inspect.getfile(reader)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'reader' is not defined

Isn't reader supposed to be part of tensorflow? How can I install this module?

I need it because in the code I am trying to run, it includes commands like this:

def gen_epochs(n, num_steps, batch_size):
    for i in range(n):
        yield reader.ptb_iterator(data, batch_size, num_steps)

Upvotes: 3

Views: 2709

Answers (3)

Mihai.Mehe
Mihai.Mehe

Reputation: 504

  1. Download the reader from github: https://raw.githubusercontent.com/tensorflow/models/master/tutorials/rnn/ptb/reader.py

and add the file path and module to your python project:

import os

import sys

scriptpath = "/My/Path/To/Module/File/" 

sys.path.append(os.path.abspath(scriptpath))

import reader
  1. Otherwise, A file can be read using:

    from tensorflow import read_file

instead of:

from tensorflow.models.rnn.ptb import reader

Upvotes: 1

Jeff Tang
Jeff Tang

Reputation: 1804

I don't think reader.py is part of http://github.com/tensorflow/tensorflow, but it's included in http://github.com/tensorflow/models. It's used in https://github.com/tensorflow/models/tree/master/tutorials/rnn/ptb and there's a commit message 3 months ago for reader.py that says "Moving example models from github.com/tensorflow/tensorflow to github.com/tensorflow/models".

In the example code ptb_word_lm.py of the tutorials/rnn/ptb, there's a import reader and I'm able to run ptb_word_lm.py successfully.

Upvotes: 0

dorien
dorien

Reputation: 5407

Tried installing tensorflow for python3, but same issue.

So I just put this reader.py file in my main folder: http://programtalk.com/vs2/?source=python/7331/tensorflow_with_latest_papers/reader.py and that seems to work.

Upvotes: 0

Related Questions