You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In creating a simple image classifier, there appears to be a bug when trying to render the output onto a Jupyter Notebook. Specifically, here's the output issue that I experience:
AttributeError: module 'numpy' has no attribute 'int'
The code deploys properly on Huggingface Spaces, but I get an error when the output is rendered on Jupyter Notebook. How can this be resolved so that I can actually create and test the output locally in Jupyter Notebook before deploying it more broadly on Huggingface Spaces? I've posted the same question under issues in the Gradio repo, but was suggested to post in the fastai repo
Traceback (most recent call last):
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\gradio\routes.py", line 321, in run_predict
output = await app.blocks.process_api(
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\gradio\blocks.py", line 1015, in process_api
result = await self.call_function(fn_index, inputs, iterator, request)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\gradio\blocks.py", line 856, in call_function
prediction = await anyio.to_thread.run_sync(
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\anyio_backends_asyncio.py", line 867, in run
result = context.run(func, *args)
File "C:\Users\tangmi2\AppData\Local\Temp\ipykernel_22992\830469006.py", line 6, in predict
pred, pred_idx, probs = learn.predict(img)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 313, in predict
inp,preds,_,dec_preds = self.get_preds(dl=dl, with_input=True, with_decoded=True)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 300, in get_preds
self._do_epoch_validate(dl=dl)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 236, in _do_epoch_validate
with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelValidException)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 193, in with_events
try: self(f'before{event_type}'); f()
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 199, in all_batches
for o in enumerate(self.dl): self.one_batch(*o)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\data\load.py", line 127, in iter
for b in _loadersself.fake_l.num_workers==0:
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\torch\utils\data\dataloader.py", line 628, in next
data = self._next_data()
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\torch\utils\data\dataloader.py", line 671, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\torch\utils\data_utils\fetch.py", line 43, in fetch
data = next(self.dataset_iter)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\data\load.py", line 138, in create_batches
yield from map(self.do_batch, self.chunkify(res))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\basics.py", line 230, in chunked
res = list(itertools.islice(it, chunk_sz))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\data\load.py", line 153, in do_item
try: return self.after_item(self.create_item(s))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 208, in call
def call(self, o): return compose_tfms(o, tfms=self.fs, split_idx=self.split_idx)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 158, in compose_tfms
x = f(x, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 81, in call
def call(self, x, **kwargs): return self._call('encodes', x, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 91, in _call
return self.do_call(getattr(self, fn), x, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 98, in do_call
res = tuple(self.do_call(f, x, **kwargs) for x in x)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 98, in
res = tuple(self.do_call(f, x, **kwargs) for x in x)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 97, in _do_call
return retain_type(f(x, **kwargs), x, ret)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\dispatch.py", line 120, in call
return f(*args, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\vision\core.py", line 236, in encodes
def encodes(self, o:PILBase): return o._tensor_cls(image2tensor(o))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\vision\core.py", line 106, in image2tensor
res = tensor(img)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\torch_core.py", line 154, in tensor
else _array2tensor(array(x), **kwargs))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\torch_core.py", line 136, in array2tensor
if sys.platform == "win32" and x.dtype==np.int: x = x.astype(np.int64)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\numpy_init.py", line 284, in getattr
raise AttributeError("module {!r} has no attribute "
System Info
Gradio Version: gradio==3.15.0
Operating System: Windows 10 Enterprise 64-bit
Browser: Microsoft Edge
The text was updated successfully, but these errors were encountered:
Describe the Bug
In creating a simple image classifier, there appears to be a bug when trying to render the output onto a Jupyter Notebook. Specifically, here's the output issue that I experience:
The code deploys properly on Huggingface Spaces, but I get an error when the output is rendered on Jupyter Notebook. How can this be resolved so that I can actually create and test the output locally in Jupyter Notebook before deploying it more broadly on Huggingface Spaces? I've posted the same question under issues in the Gradio repo, but was suggested to post in the fastai repo
Reproduction
Here's the full source code on GitHub: https://github.com/emptytank/invoice_classifier/blob/main/invoice_classifier.ipynb
Here's the Hugging face spaces: https://huggingface.co/spaces/emptytank/invoice_classifier
Here's the link to the issue posted in the Gradio GitHub repo: gradio-app/gradio#2908
Logs
Traceback (most recent call last):
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\gradio\routes.py", line 321, in run_predict
output = await app.blocks.process_api(
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\gradio\blocks.py", line 1015, in process_api
result = await self.call_function(fn_index, inputs, iterator, request)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\gradio\blocks.py", line 856, in call_function
prediction = await anyio.to_thread.run_sync(
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\anyio_backends_asyncio.py", line 867, in run
result = context.run(func, *args)
File "C:\Users\tangmi2\AppData\Local\Temp\ipykernel_22992\830469006.py", line 6, in predict
pred, pred_idx, probs = learn.predict(img)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 313, in predict
inp,preds,_,dec_preds = self.get_preds(dl=dl, with_input=True, with_decoded=True)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 300, in get_preds
self._do_epoch_validate(dl=dl)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 236, in _do_epoch_validate
with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelValidException)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 193, in with_events
try: self(f'before{event_type}'); f()
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\learner.py", line 199, in all_batches
for o in enumerate(self.dl): self.one_batch(*o)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\data\load.py", line 127, in iter
for b in _loadersself.fake_l.num_workers==0:
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\torch\utils\data\dataloader.py", line 628, in next
data = self._next_data()
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\torch\utils\data\dataloader.py", line 671, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\torch\utils\data_utils\fetch.py", line 43, in fetch
data = next(self.dataset_iter)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\data\load.py", line 138, in create_batches
yield from map(self.do_batch, self.chunkify(res))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\basics.py", line 230, in chunked
res = list(itertools.islice(it, chunk_sz))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\data\load.py", line 153, in do_item
try: return self.after_item(self.create_item(s))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 208, in call
def call(self, o): return compose_tfms(o, tfms=self.fs, split_idx=self.split_idx)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 158, in compose_tfms
x = f(x, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 81, in call
def call(self, x, **kwargs): return self._call('encodes', x, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 91, in _call
return self.do_call(getattr(self, fn), x, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 98, in do_call
res = tuple(self.do_call(f, x, **kwargs) for x in x)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 98, in
res = tuple(self.do_call(f, x, **kwargs) for x in x)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\transform.py", line 97, in _do_call
return retain_type(f(x, **kwargs), x, ret)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastcore\dispatch.py", line 120, in call
return f(*args, **kwargs)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\vision\core.py", line 236, in encodes
def encodes(self, o:PILBase): return o._tensor_cls(image2tensor(o))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\vision\core.py", line 106, in image2tensor
res = tensor(img)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\torch_core.py", line 154, in tensor
else _array2tensor(array(x), **kwargs))
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\fastai\torch_core.py", line 136, in array2tensor
if sys.platform == "win32" and x.dtype==np.int: x = x.astype(np.int64)
File "c:\Users\tangmi2\GitHub\invoice_classifier\venv-invoice\lib\site-packages\numpy_init.py", line 284, in getattr
raise AttributeError("module {!r} has no attribute "
System Info
Gradio Version: gradio==3.15.0
Operating System: Windows 10 Enterprise 64-bit
Browser: Microsoft Edge
The text was updated successfully, but these errors were encountered: