Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 449
newuser Avatar asked Apr 25 '16 22:04

newuser


2 Answers

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(...)

like image 200
Tommy Avatar answered Oct 19 '22 20:10

Tommy


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=" ")
like image 1
tauseef_CuriousGuy Avatar answered Oct 19 '22 18:10

tauseef_CuriousGuy