newuser
newuser

Reputation: 113

How to load local files in Keras?

So I started working with Keras and I was trying out the lstm_text_generation from the examples. The problem is that have a text file on local directory but the get_file method has a origin parameter which requires a file which is hosted somewhere.

I wanted to know if a local file can be used or I have to host the file online?

Upvotes: 6

Views: 17518

Answers (2)

Tommy
Tommy

Reputation: 809

The purpose of get_file is downloading a file over the network. If you want to access something on your file system, you don't need it.

In the case of the text generator, just use something like:

text = open("localfile.txt").read().lower()

and delete the line with path = get_line(...)

Upvotes: 3

tauseef_CuriousGuy
tauseef_CuriousGuy

Reputation: 800

If I have to read from a file (someDataFile.txt) into a numpy array X_train (to be used in some task by a Keras model) then I can do so like this -

X_train = np.genfromtxt(r"C:\Users\tauseef\Desktop\keras\tutorials\features\someDataFile.txt",delimiter=" ")

Upvotes: 1

Related Questions