I’ve built a website which lets a user to train a machine learning model and download it afterwards. For downloading the model, i’m taking “directory path” from user as input where he wants to download it.
Model is successfully being downloaded but two more folders namely “variable” and “asset” are being downloaded with it. Why is that? and how can i let the user to “only” download the model?
It doesn’t look like there’s anything wrong with your code. Looking at the TensorFlow docs, this is how TensorFlow saves models: “The variables directory contains a standard training checkpoint… The assets directory contains files used by the TensorFlow graph…” If you really want a single file for the saved model, you can use HDF5 format.
Hello @brooke! I’ve been really busy lately so i couldn’t give a try to the solution you provided. But today i tried to save the model in hdf5 format and it worked! the “variable” and “asset” folders didn’t appear and that’s what i wanted to do. But right now i’m struggling with saving this model in my desired directory.
This code worked perfectly (but saving the model in “C:/users/” directory). Here i’m not using the user provided path in saving the model:
@anvil.server.callable
def download(path):
if m is not None:
m.save('my_model.h5', save_format='h5')
But when i’m trying to save this in particular folder like this:
@anvil.server.callable
def download(path):
if m is not None:
m.save(path, 'my_model.h5', save_format='h5')
I’m getting the following error:
OSError: Unable to create file (unable to open file: name = 'C:\User\Desktop', errno = 13, error message = 'Permission denied', flags = 13, o_flags = 302)
at h5py/h5f.pyx, line 108
The TensorFlow docs are a great place to start for questions like these. You can read about the save method here. It looks like you are passing in an extra argument that the method doesn’t take. In future, the Anvil forums really aren’t the best place for TensorFlow-related questions.