"Variable" and "asset" folder

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?

Hi @hirasharif1998,
Could you provide a clone link for your app?

Sure.
https://anvil.works/build#clone:PWGKX63L7AD4OZVF=EMDLVKG3YBCB7ZW4NNEWX7ZF
You can find the download option in both “train and test” and “train validate and test” sections.

Server code for download the model:

@anvil.server.callable
def download(path):
    if m is not None:
        m.save(path)

This function takes path of folder where he wants to save the model (user input).

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.

3 Likes

Oh now i get it. Thanks for your time!

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

Hi @hirasharif1998,

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.

1 Like