Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using a bundled Keras model on POSIT Workbench #71

Closed
andrewbcooper opened this issue Dec 13, 2024 · 3 comments
Closed

Error when using a bundled Keras model on POSIT Workbench #71

andrewbcooper opened this issue Dec 13, 2024 · 3 comments

Comments

@andrewbcooper
Copy link

Hello! Thank yo for this amazing packages! I trained a Keras model on my laptop, bundled it, uploaded it to our POSIT Workbench environment, and then tried to use it for predictions. Unfortunately, I got the error:

Error in if (tensorflow::tf_version() < "2.0.0") stop("TensorFlow version >= 2.0.0 is requires to load models in the SavedModel format.", :
argument is of length zero

My guess it's because we don't actually have TensorFlow installed on the POSIT Workbench servers (e.g., install_tensorflow(); install_keras()) even though we have both TensorFlow and Keras packages installed. tensorflow::tf_version() returns NULL.

Is there any way to use bundle to get predictions from a Keras model without installing TensorFlow / Keras? Our IT folks say it'll probably be 6-9 months before they can get around to that :/

Thanks!

Non-reproducable code:

On my laptop:

bundled_NNModel <-
bundle(NNModel)

save(bundled_NNModel,file="bundled_NNModel.RData")

After uploading to the server....

load("bundled_NNModel.RData")
library(keras)

r(
function(model_bundle, new_data) {
library(bundle)

model_object <- unbundle(model_bundle)

predict(model_object, new_data)

},
args = list(
model_bundle = bundled_NNModel,
new_data = as.matrix(testfeatures)
)
)

@juliasilge
Copy link
Member

Unfortunately, bundling only solves the problem of how you serialize your model, not the software that you then need to use the model. For example, you likely will need bundle to store an xgboost model and use it in a new R session because of how xgboost works, but you also still need xgboost.

An option for making predictions that does not require the original R package is orbital, but currently it does not provide support for keras models.

@andrewbcooper
Copy link
Author

Thank you for your lightning-fast response! That's kind of what I figured. Thankfully, it looks like I can get around it by using torch and luz which don't require IT to do anything :) And even more thankfully, your bundle package handles those beautifully! Thanks for this amazing package!

@juliasilge
Copy link
Member

Let us know if you have further questions! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants