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

Don't install torch by default #472

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions .github/workflows/ocr-benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: OCR Poetry Benchmark Tests
on:
pull_request:
paths:
- .github/workflows/ocr-benchmarks.yml
- OCR/**
push:
branches:
- main
Expand All @@ -16,31 +20,13 @@ jobs:
python-version: "3.10"
- name: Install dependencies
run: |
sudo apt update && sudo apt install tesseract-ocr-eng tesseract-ocr
cd OCR/tests
python -m pip install --upgrade pip
pip install poetry
pip install pytest pytest-benchmark
poetry install --with dev
poetry install --with dev --with torch
- name: Run tests
run: |
cd OCR/tests
poetry run pytest benchmark_test.py -v --benchmark-json output.json
# - name: Store benchmark result
# uses: benchmark-action/github-action-benchmark@v1
# with:
# tool: 'pytest'
# output-file-path: OCR/tests/output.json
# auto-push: false
# - name: Push benchmark result
# run: git push 'https://CDCgov:${{ secrets.GITHUB_TOKEN }}@github.com/CDCgov/IDWA.git' gh-pages:gh-pages
# - name: Fetch data.js from gh-pages
# run: |
# git config --global user.name 'GitHub Action'
# git config --global user.email '[email protected]'
# git fetch
# git checkout gh-pages
# rm ./dev/bench/index.html
# cp ./dev/bench/index-template.html ./dev/bench/index.html
# git add .
# git commit -m "template to index"
# git push origin gh-pages
2 changes: 1 addition & 1 deletion .github/workflows/ocr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
sudo apt install tesseract-ocr-eng tesseract-ocr -y
python -m pip install --upgrade pip
pip install poetry
poetry install --with dev
poetry install --with dev --with torch
- name: Run tests
run: poetry run pytest tests/ocr_test.py tests/segmentation_template_test.py tests/alignment_test.py
2 changes: 1 addition & 1 deletion OCR/dev-dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY ./pyproject.toml /ocr/pyproject.toml
COPY ./poetry.lock /ocr/poetry.lock

WORKDIR /ocr
RUN poetry install && poetry cache list | xargs -n1 poetry cache clear --all
RUN poetry install --without=torch && poetry cache list | xargs -n1 poetry cache clear --all
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from pathlib import Path

import torch
import numpy as np
import cv2 as cv
from PIL import Image
Expand All @@ -20,6 +19,8 @@ def make_transform(self, distortion_scale: float) -> object:
"""
Create a transformation matrix for a random perspective transform.
"""
import torch

# From torchvision. BSD 3-clause
height = self.image.height
width = self.image.width
Expand Down
2 changes: 1 addition & 1 deletion OCR/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion OCR/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ numpy = "^1.26.4"
opencv-python = "^4.9.0.80"
levenshtein = "^0.25.1"
fastapi = {extras = ["standard"], version = "^0.112.1"}
transformers = {extras = ["torch"], version = "^4.45.1"}
pillow = "^10.3.0"
datasets = "^3.0.1"
tesserocr = "^2.7.1"

[tool.poetry.group.torch.dependencies]
transformers = {extras = ["torch"], version = "^4.45.1"}

[tool.poetry.group.dev.dependencies]
lxml = "^5.3.0"
docopt = "^0.6.2"
Expand Down
2 changes: 1 addition & 1 deletion dev-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
volumes:
- ./OCR:/ocr
restart: "no"
command: "/bin/sh -c 'poetry install && poetry run fastapi dev ocr/api.py --host 0.0.0.0 --port 8000'"
command: "/bin/sh -c 'poetry install --without=torch --sync && poetry run fastapi dev ocr/api.py --host 0.0.0.0 --port 8000'"
frontend:
build:
context: ./frontend
Expand Down
Loading