loading saved keras model from gs to pydatalab

前端 未结 4 1427
情话喂你
情话喂你 2021-01-15 03:05

My keras model is saved in google storage with model.save(model_name)

I cannot load the model on pydatalab. When I save the model on my local machine, I can just ope

4条回答
  •  礼貌的吻别
    2021-01-15 04:03

    OS level command can also be used just in case someone is using Colab

    To mound your google drive use

    from google.colab import drive
    drive.mount('/content/drive', force_remount=True)
    

    Code to mount GCS

    from google.colab import auth
    auth.authenticate_user()
    project_id = 'thirumalai_bucket'  #your bucket here
    !gcloud config set project {project_id}
    !gsutil ls
    

    !gsutil -m cp

    in your case:

    !gsutil -m cp gs://mybucket/model.h5  /content/drive/My\ Drive/models/ 
    

    now the file model.h5 available in drive /content/drive/My Drive/models/ move to your models directory using:

    !cd /content/drive/My\ Drive/models/
    
    load_model('model.h5')
    

    Hope this helps!

提交回复
热议问题