Skip to content

Commit

Permalink
Some consistency and pipeline for releasing models.zip file
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhuomkar committed Feb 8, 2024
1 parent 35f4735 commit 8cbe833
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
name: Release ML Models
runs-on: ubuntu-latest
env:
VERSION: ${{ github.ref_name }}
defaults:
run:
working-directory: ./ml
Expand All @@ -21,4 +23,13 @@ jobs:
run: python -c "import sys; print(sys.version)"
- name: Install Dependencies
run: make install
- name: Create models
run: |
make all
zip -r models.zip classification/*.pt faces/*.pt ocr/cls_onnx ocr/det_onnx ocr/rec_onnx search/*.pt search/search_processor search/search_tokenizer
- name: Create release asset
uses: softprops/action-gh-release@v1
with:
files: |
models.zip
4 changes: 2 additions & 2 deletions ml/faces/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
def download_and_save():
"""Download models for detection, recognition and classification"""
print('downloading and saving pytorch models')
urllib.request.urlretrieve('https://github.com/timesler/facenet-pytorch/releases/download/v2.2.9/20180402-114759-vggface2.pt', 'vggface2.pt')
urllib.request.urlretrieve('https://github.com/timesler/facenet-pytorch/releases/download/v2.2.9/20180402-114759-vggface2.pt', '20180402-114759-vggface2.pt')

def load_and_run(sample='example.jpg'):
"""Loads the saved pytorch models and runs sample image"""
print('loading and running pytorch models')
os.environ['TORCH_HOME'] = os.getcwd()
try:
os.symlink(os.getcwd(), f'{os.getcwd()}/checkpoints')
os.symlink(f'{os.getcwd()}', f'{os.getcwd()}/checkpoints')
except:
pass
det_model = MTCNN(keep_all=True)
Expand Down
9 changes: 6 additions & 3 deletions ml/ocr/paddlepaddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def download_and_save():
shutil.rmtree('cls_infer')
urllib.request.urlretrieve('https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.7/ppocr/utils/en_dict.txt', 'rec_onnx/en_dict.txt')

def load_and_run(sample):
def load_and_run(sample='example.jpg'):
"""Loads the saved paddle ocr models and runs sample image"""
print('loading and running paddle ocr models')
import fastdeploy as fd
Expand All @@ -82,7 +82,7 @@ def load_and_run(sample):
runtime_option=default_option, model_format=fd.ModelFormat.ONNX)
rec_model = fd.vision.ocr.Recognizer(
model_file='rec_onnx/model.onnx',
label_path='rec_infer/en_dict.txt', runtime_option=default_option, model_format=fd.ModelFormat.ONNX)
label_path='rec_onnx/en_dict.txt', runtime_option=default_option, model_format=fd.ModelFormat.ONNX)
ocr = fd.vision.ocr.PPOCRv3(det_model=det_model, cls_model=cls_model, rec_model=rec_model)
result = ocr.predict(cv2.imread(sample))
print(result.text)
Expand All @@ -94,6 +94,9 @@ def load_and_run(sample):
download_and_save()
exit(0)
if args[1] == 'run':
load_and_run(args[2])
if len(args) == 3:
load_and_run(args[2])
else:
load_and_run()
exit(0)
print('provide a valid arg: save OR run')

0 comments on commit 8cbe833

Please sign in to comment.