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

feat: Added pretrained PyTorch mobilenets #415

Merged
merged 2 commits into from
Aug 13, 2021
Merged

Conversation

fg-mindee
Copy link
Contributor

Following up on #255, this PR introduces the following modifications:

  • adds pretrained params for PyTorch mobilenets (character classification)
  • updated unittests
import torch
from doctr.models import mobilenet_v3_small
from doctr.datasets import VOCABS
from doctr.datasets.classification.base import synthesize_char_img
from doctr.io import tensor_from_pil
from torchvision.transforms import Normalize

model = mobilenet_v3_small(pretrained=True).eval()
img = synthesize_char_img('a', font_family='FreeMono.ttf')
transfo = Normalize(mean=(0.694, 0.695, 0.693), std=(0.299, 0.296, 0.301))

with torch.no_grad():
    out = model(transfo(tensor_from_pil(img)))

print(VOCABS['french'][out.argmax().item()])

yields:

'a'

Any feedback is welcome!

@fg-mindee fg-mindee added module: models Related to doctr.models ext: tests Related to tests folder framework: pytorch Related to PyTorch backend labels Aug 13, 2021
@fg-mindee fg-mindee added this to the 0.4.0 milestone Aug 13, 2021
@fg-mindee fg-mindee self-assigned this Aug 13, 2021
@codecov
Copy link

codecov bot commented Aug 13, 2021

Codecov Report

Merging #415 (fe64d05) into main (350a961) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #415      +/-   ##
==========================================
+ Coverage   95.78%   95.83%   +0.04%     
==========================================
  Files          95       96       +1     
  Lines        3917     3937      +20     
==========================================
+ Hits         3752     3773      +21     
+ Misses        165      164       -1     
Flag Coverage Δ
unittests 95.83% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
doctr/models/backbones/mobilenet/__init__.py 100.00% <100.00%> (ø)
doctr/models/backbones/mobilenet/pytorch.py 100.00% <100.00%> (ø)
doctr/models/core.py 94.95% <0.00%> (+0.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 350a961...fe64d05. Read the comment docs.

@fg-mindee fg-mindee merged commit 94e984c into main Aug 13, 2021
@fg-mindee fg-mindee deleted the trained-mobilenets branch August 13, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: tests Related to tests folder framework: pytorch Related to PyTorch backend module: models Related to doctr.models
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant