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

bear_classifier notebook not working on Binder #5

Open
the-lazy-val opened this issue Oct 8, 2020 · 7 comments
Open

bear_classifier notebook not working on Binder #5

the-lazy-val opened this issue Oct 8, 2020 · 7 comments

Comments

@the-lazy-val
Copy link

Hi, I am just starting with fastai.
I forked the fastai/bear_voila repo (to this repo), and set it up in Binder.
https://mybinder.org/v2/gh/the-lazy-val/bear_classifier/master?filepath=%2Fvoila%2Frender%2Fbear_classifier.ipynb

After app launch, I get the below error:
There was an error when executing cell [2]. Please run Voilà with --debug to see the error message.

I am using the same pre-trained model (export.pkl) that is already available in the repo.

@mlapeter
Copy link

@the-lazy-val I ran into this same issue. I haven't yet resolved it, but did find an alternate way to publish using Voila:

In your paperspace notebook (I'm using V2), click the Volia button in the top menu (far right):

image

You should see your working bear classifier open in a new tab. To share, add ?token= plus your notebook token to that url, for example: https://n9eusla3.gradient.paperspace.com/voila/render/fastbook/BearBot.ipynb?token=putyourtokenhere

You can copy your token from the main paperspace notebooks page: https://console.paperspace.com/notebooks:

image

I'm still new to paperspace and haven't researched implications of sharing your token publicly, but using above you should be able to share at least with trusted people and run from any computer.

@MarissaFernandes22
Copy link

Yes I've faced the same issue. I've spent hours on it and can't find the solution yet :/ As @mlapeter suggested, voila works well using Paperspace.

@tkravichandran
Copy link

Reproduced the same thing as shown here.

@nanospeck
Copy link

nanospeck commented Oct 22, 2020

I'm facing the same issue. Seems original repo is working fine in binder because the environment was built already before something broke in binder? Even new binder requests for original repo is working fine and showing as the environment is already build.
Any solutions for forks?

@nanospeck
Copy link

nanospeck commented Oct 22, 2020

As temporary workaround is to follow this link:
https://forums.fast.ai/t/load-learner-attributeerror-cant-get-attribute-flattenedloss-on-module-fastai-layers/78117/10

Just add this to the first code block:

import fastai.losses
import fastai.layers

fastai.layers.BaseLoss = fastai.losses.BaseLoss
fastai.layers.CrossEntropyLossFlat = fastai.losses.CrossEntropyLossFlat
fastai.layers.BCEWithLogitsLossFlat = fastai.losses.BCEWithLogitsLossFlat
fastai.layers.BCELossFlat = fastai.losses.BCELossFlat
fastai.layers.MSELossFlat = fastai.losses.MSELossFlat
fastai.layers.L1LossFlat = fastai.losses.L1LossFlat
fastai.layers.LabelSmoothingCrossEntropy = fastai.losses.LabelSmoothingCrossEntropy
fastai.layers.LabelSmoothingCrossEntropyFlat = fastai.losses.LabelSmoothingCrossEntropyFlat

@tkravichandran
Copy link

tkravichandran commented Oct 22, 2020

@nanospeck

Em, this assumes that we trained a model with fastai <2.0 and want to deploy with fastai>2.0.

However I have the error in with the latest fastai (>2.0) trained model being deployed at binder.

Edit: Heroku seems like a better app to deploy with functions to --debug. If interested have a look here

@supermaxJ
Copy link

Hi, @the-lazy-val and all,
Faced the same issue too. Now I savled this problem. I found that the problem was due to a mismatch between.pkl and some other packages. I updated my requiretments.txt, add runtime.txt, and change some code to fix it.
This is my requiretments.txt and runtime.txt.

requirements.txt

voila
fastai>=2,<=2.0.6
fastcore==1.0.0
pillow<7
packaging
ipywidgets==8.0.0
torch==1.6.0

runtime.txt

python-3.8.6

and change the code

def on_data_change(change):
    lbl_pred.value = ''
    img = PILImage.create(btn_upload.value[0].content.tobytes())
    out_pl.clear_output()
    with out_pl: display(img.to_thumb(128,128))
    pred,pred_idx,probs = learn_inf.predict(img)
    lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'


btn_upload.observe(on_data_change, names=['value'])

my forked repo
https://github.com/supermaxJ/bear_voila_copy

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

6 participants