Spaces:
Running
Running
Andrey
commited on
Commit
•
cf41825
1
Parent(s):
3c1f8e4
Create python-app.yml (#4)
Browse files* Create python-app.yml
Add ci/cd
* Update ci cd.
* Fixes for mypy.
* Add a basic test.
* Add a basic test.
* Remove tests for now.
- .github/workflows/ci.yml +0 -53
- .github/workflows/python-app.yml +48 -0
- src/ml_utils.py +6 -6
- src/utils.py +2 -2
.github/workflows/ci.yml
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
# This is a basic workflow to help you get started with Actions
|
2 |
-
# some parts are taken from here: https://github.com/ternaus/iglovikov_helper_functions/blob/master/.github/workflows/ci.yml
|
3 |
-
name: CI
|
4 |
-
|
5 |
-
# Controls when the action will run. Triggers the workflow on push or pull request
|
6 |
-
# events but only for the master branch
|
7 |
-
on:
|
8 |
-
push:
|
9 |
-
branches: [ master ]
|
10 |
-
pull_request:
|
11 |
-
branches: [ master ]
|
12 |
-
|
13 |
-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
14 |
-
jobs:
|
15 |
-
# This workflow contains a single job called "build"
|
16 |
-
build:
|
17 |
-
# The type of runner that the job will run on
|
18 |
-
runs-on: ubuntu-latest
|
19 |
-
|
20 |
-
# Steps represent a sequence of tasks that will be executed as part of the job
|
21 |
-
steps:
|
22 |
-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
23 |
-
- uses: actions/checkout@v2
|
24 |
-
- name: Set up Python
|
25 |
-
uses: actions/setup-python@v2
|
26 |
-
with:
|
27 |
-
python-version: '3.9.15'
|
28 |
-
- name: Cache pip
|
29 |
-
uses: actions/cache@v1
|
30 |
-
with:
|
31 |
-
path: ~/.cache/pip # This path is specific to Ubuntu
|
32 |
-
# Look to see if there is a cache hit for the corresponding requirements file
|
33 |
-
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
|
34 |
-
restore-keys: |
|
35 |
-
${{ runner.os }}-pip-
|
36 |
-
${{ runner.os }}-
|
37 |
-
# You can test your matrix by printing the current Python version
|
38 |
-
- name: Display Python version
|
39 |
-
run: python -c "import sys; print(sys.version)"
|
40 |
-
- name: Install dependencies
|
41 |
-
run: |
|
42 |
-
python -m pip install --upgrade pip
|
43 |
-
pip install -r requirements.txt
|
44 |
-
pip install black flake8 mypy pytest
|
45 |
-
- name: Run black
|
46 |
-
run:
|
47 |
-
black --check .
|
48 |
-
- name: Run flake8
|
49 |
-
run: flake8
|
50 |
-
- name: Run Mypy
|
51 |
-
run: mypy --ignore-missing-imports --warn-no-return --warn-redundant-casts --disallow-incomplete-defs .
|
52 |
-
- name: tests
|
53 |
-
run: pytest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.github/workflows/python-app.yml
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
2 |
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
3 |
+
|
4 |
+
name: Python application
|
5 |
+
|
6 |
+
on:
|
7 |
+
push:
|
8 |
+
branches: [ "main" ]
|
9 |
+
pull_request:
|
10 |
+
branches: [ "main" ]
|
11 |
+
|
12 |
+
permissions:
|
13 |
+
contents: read
|
14 |
+
|
15 |
+
jobs:
|
16 |
+
build:
|
17 |
+
|
18 |
+
runs-on: ubuntu-latest
|
19 |
+
|
20 |
+
steps:
|
21 |
+
- uses: actions/checkout@v3
|
22 |
+
- name: Set up Python 3.10
|
23 |
+
uses: actions/setup-python@v3
|
24 |
+
with:
|
25 |
+
python-version: "3.10"
|
26 |
+
- name: Cache pip
|
27 |
+
uses: actions/cache@v1
|
28 |
+
with:
|
29 |
+
path: ~/.cache/pip # This path is specific to Ubuntu
|
30 |
+
# Look to see if there is a cache hit for the corresponding requirements file
|
31 |
+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
|
32 |
+
restore-keys: |
|
33 |
+
${{ runner.os }}-pip-
|
34 |
+
${{ runner.os }}-
|
35 |
+
- name: Install dependencies
|
36 |
+
run: |
|
37 |
+
python -m pip install --upgrade pip
|
38 |
+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
39 |
+
pip install black flake8 mypy pytest
|
40 |
+
- name: Lint with flake8
|
41 |
+
run: |
|
42 |
+
# stop the build if there are Python syntax errors or undefined names
|
43 |
+
flake8
|
44 |
+
- name: Run black
|
45 |
+
run:
|
46 |
+
black --check .
|
47 |
+
- name: Run Mypy
|
48 |
+
run: mypy --ignore-missing-imports --warn-no-return --warn-redundant-casts --disallow-incomplete-defs --no-namespace-packages .
|
src/ml_utils.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
from typing import List
|
2 |
import logging
|
|
|
3 |
|
4 |
import albumentations as A
|
5 |
import streamlit as st
|
@@ -26,8 +26,8 @@ transforms = A.Compose(
|
|
26 |
|
27 |
|
28 |
def cells_to_bboxes(
|
29 |
-
predictions: torch.
|
30 |
-
) ->
|
31 |
"""
|
32 |
Scale the predictions coming from the model_files to
|
33 |
be relative to the entire image such that they for example later
|
@@ -106,8 +106,8 @@ def non_max_suppression(
|
|
106 |
|
107 |
|
108 |
def intersection_over_union(
|
109 |
-
boxes_preds: torch.
|
110 |
-
) -> torch.
|
111 |
"""
|
112 |
Calculate iou.
|
113 |
|
@@ -156,7 +156,7 @@ def intersection_over_union(
|
|
156 |
|
157 |
|
158 |
def predict(
|
159 |
-
model: torch.nn.Module, image: torch.
|
160 |
) -> List[List]:
|
161 |
"""
|
162 |
Apply the model_files to the predictions and to postprocessing
|
|
|
1 |
import logging
|
2 |
+
from typing import List
|
3 |
|
4 |
import albumentations as A
|
5 |
import streamlit as st
|
26 |
|
27 |
|
28 |
def cells_to_bboxes(
|
29 |
+
predictions: torch.Tensor, tensor_anchors: torch.Tensor, s: int, is_preds: bool = True
|
30 |
+
) -> List[List]:
|
31 |
"""
|
32 |
Scale the predictions coming from the model_files to
|
33 |
be relative to the entire image such that they for example later
|
106 |
|
107 |
|
108 |
def intersection_over_union(
|
109 |
+
boxes_preds: torch.Tensor, boxes_labels: torch.Tensor, box_format: str = 'midpoint'
|
110 |
+
) -> torch.Tensor:
|
111 |
"""
|
112 |
Calculate iou.
|
113 |
|
156 |
|
157 |
|
158 |
def predict(
|
159 |
+
model: torch.nn.Module, image: torch.Tensor, iou_threshold: float = 1.0, threshold: float = 0.05
|
160 |
) -> List[List]:
|
161 |
"""
|
162 |
Apply the model_files to the predictions and to postprocessing
|
src/utils.py
CHANGED
@@ -3,12 +3,12 @@ from typing import List, Dict
|
|
3 |
import matplotlib
|
4 |
import matplotlib.patches as patches
|
5 |
import matplotlib.pyplot as plt
|
6 |
-
import numpy as
|
7 |
import tomli as tomllib
|
8 |
|
9 |
|
10 |
def plot_img_with_rects(
|
11 |
-
img:
|
12 |
) -> matplotlib.figure.Figure:
|
13 |
"""
|
14 |
Plot image with rectangles.
|
3 |
import matplotlib
|
4 |
import matplotlib.patches as patches
|
5 |
import matplotlib.pyplot as plt
|
6 |
+
import numpy.typing as npt
|
7 |
import tomli as tomllib
|
8 |
|
9 |
|
10 |
def plot_img_with_rects(
|
11 |
+
img: npt.ArrayLike, boxes: List[List], threshold: float = 0.5, coef: int = 400
|
12 |
) -> matplotlib.figure.Figure:
|
13 |
"""
|
14 |
Plot image with rectangles.
|