User Tools

Site Tools


googlecloud

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
googlecloud [2017/09/05 20:06]
humphrey created
googlecloud [2021/06/30 23:42] (current)
Line 1: Line 1:
 +====== Deep Learning on the Google Cloud Platform ======
 +
 +
 +==== Installing gcloud on a local machine ====
 +
 1. Install gcloud sdk on your local machine (I personally used window linux subsystem, therefore I chose the apt-get option) 1. Install gcloud sdk on your local machine (I personally used window linux subsystem, therefore I chose the apt-get option)
 reference: https://​cloud.google.com/​sdk/​downloads reference: https://​cloud.google.com/​sdk/​downloads
  
-2. Call "​gcloud init" on the command line, set user account, ​set region of computation unit.+2. Use the following code to setup user account, ​including setting ​region of computation unit.
  
-3. On the web api, click on storage, and create a new storage bucket if there hasn't been one. Let's call it byu_tf_ml ​for our example.+<​code>​ gcloud init </​code>​ 
 + 
 +---- 
 +==== Setup google cloud storage device ==== 
 + 
 +3. On the web api (link: https://​console.cloud.google.com)click on the drop down manual on the top left hand corner -> click on storage ​-> click on browse, and create a new storage bucket if there hasn't been one. Let's call it byu_tf_ml ​in this example. 
 + 
 +---- 
 +==== Submit a learning job to google cloud ==== 
 + 
 +4. On the local machine console, call the following command: 
 +<​code>​  
 +gcloud ml-engine jobs submit training  
 + [job_id] 
 + --package-path [scource_dir]  
 + --module-name [scource_dir.main_script]  
 + --staging-bucket gs://​[save_to_directory] 
 + --scale-tier BASIC_GPU 
 +</​code>​
  
-4. On the local machine console, call: gcloud ml-engine jobs submit training my_job --package-path ./trainer --module-name trainer.py_task --staging-bucket gs://​byu_tf_ml --scale-tier BASIC 
 reference: https://​cloud.google.com/​sdk/​gcloud/​reference/​ml-engine/​jobs/​submit/​training reference: https://​cloud.google.com/​sdk/​gcloud/​reference/​ml-engine/​jobs/​submit/​training
-hints: this step is a bit tricky, the command "​gcloud ml-engine jobs submit training"​ is a google cloud version of packaging up our python machine learning project and uploading that to the cloud platform and run it. There are four fields required: 
-a. job: in our example, the value is my_job, it's the job id showing up in the web api after submitting the job. 
-b. package-path:​ the local machine directory which contains the python source code. 
-c. module-name:​ the main python script. 
-d. staging-bucket:​ the place on google cloud where the ml model is stored. 
  
-optional: +The command "​gcloud ml-engine jobs submit training"​ is a google cloud version to package up our python machine learning job, uploading that to the cloud platform and then run it on some cloud machines. There four fields are required: 
-e. scale-tier: ​this is optionalbut allow a fine control on how much computation power we want to use with the project+ 
-f. package-paththe path where packages you imported into the project but not listed here: https://​cloud.google.com/​ml-engine/​docs/​concepts/​runtime-version-list+ a. job: In our example, the value is [job_id] in the example, it's the job id showing up in the web api after submitting the job. 
 +   
 + b. package-path:​ The local machine directory which contains the python source code. 
 +   
 + c. module-name:​ The main python script. 
 +   
 + d. staging-bucket:​ The place on google cloud in which the machine learning source code is stored. 
 + 
 +and these are optional: 
 + 
 + e. scale-tier: ​There are BASICBASIC_GPU, PREMIUM_1, STANDARD_1, CUSTOM, five different tiers, standing for different level of resources ​to be used. 
 +  
 + ​f. ​packagesThe path where packages you imported into the project but not listed here: https://​cloud.google.com/​ml-engine/​docs/​concepts/​runtime-version-list 
 + 
 +---- 
 +===Hints:​=== 
 +  
 +1. In order to save and retrieve data on google cloud machines, specify the path of input and output as <​code>​gs://​[bucket_name]/​[io_directory]</​code>​ 
 + 
 +2. Python cannot realize "​gs:"​ prefix, we need to use "​tf.gfile.Open"​ to import file, for example: 
 +<code python>​ 
 +def unpickle( file ): 
 + import cPickle 
 + with tf.gfile.Open(file,​ '​rb'​) as fo: 
 + dic = cPickle.load(fo) 
 + return dic 
 +</​code>​ 
 + 
 +3. You need a <​code>​__init__.py</​code>​ file in your source code directory in order to make it work. You can keep it as an empty file. 
 + 
 +---- 
 +==== Check the results ==== 
 + 
 +1. On the web api, click on the drop down manual on the top left hand corner -> click on ML Engine -> click on job. You should be able to see the project submitted. 
 + 
 +2. After the training finished, you will be able to see the results and logs under corresponding job. And if there are any outputs from your job, they should have been stored in the corresponding folder under the gs path.
  
-5On the web api, go to ML Engine and click on job, you should be able to see the project submitted.+3Run the following command in Cloud Shell to start TensorBoard. 
 +<​code>​ tensorboard --port 8080 --logdir gs://​[bucket_name]/​[output_directory] </​code>​
  
-6After the training finishedyou will be able to see the results and logs on the web api.+4To open a new browser windowselect Preview ​on port 8080 from the Web preview menu in the top-right corner of the Cloud Shell toolbar.
  
-Others: +---- 
-7. If you want to reuse the trained weights of of the model, include the savedmodel function in the application. +==== Related resources ==== 
-reference: https://​cloud.google.com/​ml-engine/​docs/​concepts/​prediction-overview+1. If you want to reuse the trained weights of of the model, include the savedmodel function in the application. 
 +Reference: https://​cloud.google.com/​ml-engine/​docs/​concepts/​prediction-overview
  
-8I haven'​t try out tensorbroad yet, but it seems like that it's not too bad to achieve. +2You may want to check out more examples onlineReference: https://​cloud.google.com/​sdk/​gcloud/​reference/ml-engine/jobs/submit/training
-reference: https://​cloud.google.com/​ml-engine/​docs/how-tos/monitor-training#​monitoring_with_tensorboard+
googlecloud.1504641962.txt.gz · Last modified: 2021/06/30 23:40 (external edit)