none
Publishing Tensorflow models RRS feed

  • Question

  • Hi All,

    I am unable to publish tensorflow models, below are the different publish codes which i have tried but no luck...

    1)   api <- publishService(
      "myPrediction",
      code = predict,
      model = load_model_hdf5("c:\\mypredictions\\NikonNN2.h5"),
      inputs = list(filename = "character"),
      outputs = list(answer = "data.frame"),
      v = "v1.0.6"
    )

    Exception:

    Error: The `model` argument can not be a function.

    2)  api <- publishService(
      "myPrediction",
      code = predict,
      model = "c:\\mypredictions\\NikonNN2.h5",
      inputs = list(filename = "character"),
      outputs = list(answer = "data.frame"),
      v = "v1.0.6"
    )

    Exception:

    Error in gzfile(file, "wb") : cannot open the connection
    In addition: Warning message:
    In gzfile(file, "wb") :
      cannot open compressed file 'C:\Users\meenigar\AppData\Local\Temp\7\Rtmp8yfQU3\NikonNN2.h5"14a503854141d.RData', probable reason 'Invalid argument'


    And the predict function will use the tensorflow model, for prediction. Could you please suggest on how can we publish models other than the ".RData" files


    Regards,

    Aravind


    Friday, March 30, 2018 2:13 PM

All replies

  • can you try this : 

    mymodel <- load_model_hdf5("c:\\mypredictions\\NikonNN2.h5")

    api <- publishService(
      "myPrediction",
      code = predict,
      model = mymodel,
      inputs = list(filename = "character"),
      outputs = list(answer = "data.frame"),
      v = "v1.0.6"
    )

    Thursday, May 3, 2018 12:19 AM
  • Keras\Tensorflow models can be published using snapshot:

    #log into remote session and load dependencies and model files
    remoteLogin(..., session = TRUE)
    pause()
    putLocalFile("my_model.h5")\
    resume()
    createSnapshot("snapshot_name") #generate a snapshot id
    exit
    
    #create a function where the model is loaded
    kerasFunc <- function(x) {
      library(keras)
      aModel = load_model_hdf5('my_model.h5', custom_objects = NULL, compile = TRUE)
      prediction <- aModel %>% predict_classes(x)
      answer = as.list(prediction)
    }
    
    #publish the web service to the snapshot id
    remoteLogin(..., session = FALSE)
    api <- publishService(
      serviceName,
      code = kerasFunc,
      snapshot = "{snapshot_id}", #fill in the snapshot id
      inputs = list(x="matrix"),
      outputs = list(answer="vector"),
      v = "v1.0.0"
    )
    


    Thursday, May 17, 2018 5:24 PM