Model taking too long to download

What I’m trying to do:
I’m building a website for a user to train image classification model. Afterwards i’m providing a download button to download the trained model. It is working perfectly but the model is taking too long to download it. Around 10 to 15 minutes, but when i’m trying to download the model without anvil, it is just taking few seconds to download. Why is that? and how can i minimize the time taken?

What I’ve tried and what’s not working:
I am using the following code to download the model. The variable “m2” contains the tensorflow model which i intend to download.

Server code:

@anvil.server.callable
def download():
    if m2 is not None:
        saved = m2.save('my_model.h5', save_format='h5')
        import anvil.media
        media_obj = anvil.media.from_file('my_model.h5')
        return media_obj
    else:
        return None

Anvil code:

  def button_1_click(self, **event_args):
    text_file = anvil.server.call('download')

    if text_file == None:
      print("Model is not ready to download")

    else:
      anvil.media.download(text_file)

There are alot of things going on in the website, therefore not sharing the clone link to avoid the mess.

Please provide assistance regarding this issue.

Hi there, it is Easter weekend for many and most folks here are volunteers. You may have to wait until Tuesday or later. No need to bump the thread.

1 Like

One way to tackle this is to compress the file, e.g., using Python’s built-in compression library.

This may be a good idea for other reasons, as well.

  1. Zipfiles offer a way to verify that the file was downloaded without corruption, i.e., an integrity check.
  2. If you’re storing these files in a database, it will take less space and time to save and retrieve them.
  3. A zipfile can contain multiple files, if needed, e.g., readme, license, etc.

Impossible to tell, unless you disclose the exact situation for the “without anvil” case. If it turns out that you’re “downloading” from one folder to another on the same computer, or on a local network, then those “downloads” are using much faster data links, and have far fewer stops along the data’s route.

1 Like

It means when i am using only jupyter notebook to train and download my model, time taken is a few seconds. But when i am doing the same task through uplinking my website using button clicks of anvil, it is taking too long to download it. Training is not taking much time, but i’m worrying about the only ‘downloading’ part of model through anvil. Since anvil is first converting the model into a ‘media object’ and then letting the user download it.

This provides no additional information about how the download itself is occurring, in this situation, so there’s still no good way for anyone to compare the mechanics against Anvil’s methods.

So I’ll make a guess. “Downloading from your jupyter notebook” entails making only one trip, from your local hard disk (where the notebook is running) to another location on your local hard disk. This would be expected to be fast, as there is no real networking involved at all.

If this is not the case, please feel free to elaborate.

In contrast, using Uplink, your data first is transmitted to one of Anvil’s servers, located in England, via Internet, then from there to the end-user’s browser, whereever that might be located, again via Internet. Thus, the Internet speeds, in each direction, will be relevant.

Case in point: when I started working with Anvil, I had a 3Mbps connection from AT&T. (1Mbps upload speed. DSL.) So receiving data (from anywhere) was slow, and sending data (to anywhere) was even slower. For the size of files we were transmitting, it made the transatlantic network lag (we’re located across the pond from Cambridge) look trivial.

Compressing our data helped a great deal. File size shrank to less than 1/10th of the original size, and with it, the transmission time.

Then we switched to a 100Mbps connection from Spectrum, and it made an immense difference. It is now fast enough for us to back up our entire set of Anvil tables, compressed data and all, in just a few minutes.

3 Likes

Thank you for your response. I got the idea :smile: