0

GCPマシンラーニングでは、.csvファイルに中間出力を使用してトレーニングジョブを実行しようとしています。私はPythonでTensorflowを使用しています。 IOError: [Errno 2] No such file or directoryGCP Machine Learningの仕事:行を.csv出力ファイルに印刷する方法は?

2.

gcs_file = gcs.open(filename, 
         'w', 
         content_type='text/plain', 
         options={'x-goog-meta-foo': 'foo', 
           'x-goog-meta-bar': 'bar'}, 
         retry_params=write_retry_params) 
    gcs_file.write('abcde\n') 
    gcs_file.write('f'*1024*4 + '\n') 
    gcs_file.close() 

...スロー:

1.

with open('gs://<bucket>/<file>', 'wt') as csv_file: 

...は、例外がスローされます:ここで

は、私がこれまで試したものです例外from google.appengine.api import app_identity ImportError: No module named appengine.api

ご存じですか?

答えて

2

を置き換えます。

tf.gfileモジュールは、TensorFlowのC++ I/Oレイヤーを使用します。このレイヤーには、GCSとの読み書きのサポートが含まれています。組み込みのPython open()関数は、ローカルファイルシステム内のファイルのみを開きます。

+0

が機能しましたありがとうございました! –

1

App Engine環境用のコードを作成しているようですが、コードを記述するのに正しい環境が正しいことは確かですか?

通常のGCPインスタンスを使用している場合は、おそらくone of the other APIsを使用してください。

from google.cloud import storage 

def upload_blob(bucket_name, source_file_name, destination_blob_name): 
    """Uploads a file to the bucket.""" 
    storage_client = storage.Client() 
    bucket = storage_client.get_bucket(bucket_name) 
    blob = bucket.blob(destination_blob_name) 

    blob.upload_from_filename(source_file_name) 

    print('File {} uploaded to {}.'.format(
     source_file_name, 
     destination_blob_name)) 

編集:あなたがTensorFlowを使用している場合(1)、あなたは書き込みのためGCSでファイルを開くためにtf.gfile.Open("gs://...", mode="w")を使用することができますオプションのためにAPIリンク

+0

シンプルで上品な答えです。 – GAEfan

関連する問題