Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Storage (gs) wrapper file input/out for Cloud ML?

Google recently announced the Clould ML, https://cloud.google.com/ml/ and it's very useful. However, one limitation is that the input/out of a Tensorflow program should support gs://.

If we use all tensorflow APIS to read/write files, it should OK, since these APIs support gs://.

However, if we use native file IO APIs such as open, it does not work, because they don't understand gs://

For example:

 with open(vocab_file, 'wb') as f:
        cPickle.dump(self.words, f)

This code won't work in Google Cloud ML.

However, modifying all native file IO APIs to tensorflow APIs or Google Storage Python APIs is really tedious. Is there any simple way to do this? Any wrappers to support google storage systems, gs:// on top of the native file IO?

As suggested here Pickled scipy sparse matrix as input data?, perhaps we can use file_io.read_file_to_string('gs://...'), but still this requrements significant code modifcation.

like image 550
Sung Kim Avatar asked Nov 03 '16 08:11

Sung Kim


People also ask

How do I upload data to Google Cloud Storage?

Drag and drop the desired files from your desktop or file manager to the main pane in the Google Cloud console. Click the Upload Files button, select the files you want to upload in the dialog that appears, and click Open.

How do I upload files from Google Cloud Storage to spring boot?

Create a Spring Boot service This is a basic Spring Boot application with a single API. In this application, the selected file will be saved in the server and then uploaded into Google Cloud Storage. The file name and cloud URL will be saved in the database. ( I used the H2 database for the development.


1 Answers

Do it like this:

from tensorflow.python.lib.io import file_io

with file_io.FileIO('gs://.....', mode='w+') as f:
    cPickle.dump(self.words, f)

Or you can read pickle file in like this:

file_stream = file_io.FileIO(train_file, mode='r')
x_train, y_train, x_test, y_test  = pickle.load(file_stream)
like image 52
Fuyang Liu Avatar answered Oct 31 '22 04:10

Fuyang Liu