I have created a pretty useful model and I would like to start using it for some simple image classification. The problem is that work machines are running windows 10 and they have absolutely 0 connection to the internet (nor can we give them that).
Is there a fast and easy way to use a pretrained model just to predict based on image input? Fastai is amazing when it comes to training but I am finding a lack in ability to be able to use these models easily in production.
You can export a model with learner.export() to a pkl-File.
Load it like this -->
Here is an example --> https://github.com/berndheidemann/notebooks_fastai/blob/master/camvid_using_the_model.ipynb
Thank you, but can you predict using a pkl file outside of fastai? I am looking for a more streamlined way of running images through a model that I have trained. Something that doesn’t need me to install the whole fastai stack on a windows machine.
In general not really, be prepared to have to dig a bit into how Python loading works and deal with a few issues.
You could probably eliminate the fastai dependency by getting the model out of your Learner and running it directly. Though you’ll then need to deal with converting your input images to tensors. You would also need to take care to perform any of the input processing fastai does in it’s data loaders such as normalisation and resizing. But even if you do eliminate fastai you would still need PyTorch, which is a sizeable dependency and can’t be eliminated.
You could try a Python to exe packer, a quick google should find various options, I’m not well versed in any so couldn’t recommend any particular one. Though I suspect they may have issues with the various non-Python dependencies of PyTorch (cuda and other acceleration libraries that are likely present even in the cpu only version).
Assuming that size isn’t really a big deal as long as it fits on a thumb drive, you could archive an Anaconda or Pip virtual environment. A quick search for “anaconda environment offline” shows that this doesn’t seem trivial with Anaconda which need various stuff installed in the root environment to function. Though there is https://github.com/conda/constructor
Or you might try a pip virtual environment instead. They seem to make more minimal usage of centrally installed stuff. Just archiving a pip environment folder and setting up path to point to it’s bin directory may work.
If you have any IT guys with experience with software repackaging talk to them. If your machines lack internet access you may well have such people with tools for this sort of thing (though tools for simple MSI repackaging may not work for Python stuff).
Thank you so much for such a thoughtful reply. I will look in to anaconda and see what I can put together. Best case scenario can make a exe directly, but I agree that seems like it might be impossible. But a exe would be amazing.