Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/latest'
Browse files Browse the repository at this point in the history
  • Loading branch information
OPHoperHPO committed May 9, 2022
2 parents f255eac + 2bc9faf commit e3f1374
Show file tree
Hide file tree
Showing 352 changed files with 18,271 additions and 12,846 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

110 changes: 110 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Test Master CPU CI/CD

on:
push:
branches: [ master ]

jobs:
test_ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip3 install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
pip3 install --no-cache-dir -r requirements_test.txt
- name: Download all models
run: |
python3 -c "from carvekit.ml.files.models_loc import download_all; download_all();"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest -s -v
# - name: Packing a docs folder in a zip archive
# run: |
# zip -r docs.zip ./docs/
# - name: Upload docs folder
# uses: actions/upload-artifact@v1
# with:
# name: generated_docs_examples.zip
# path: docs.zip
# - name: Push to Docker Hub
# uses: docker/build-push-action@v1.1.0
# with:
# tags: merge-to-nontested
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
# repository: anodev/image-background-remove-tool
# tag_with_ref: true
test_windows:
runs-on: windows-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip3 install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
pip3 install --no-cache-dir -r requirements_test.txt
- name: Download all models
run: |
python3 -c "from carvekit.ml.files.models_loc import download_all; download_all();"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest -s -v
test_macos:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip3 install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
pip3 install --no-cache-dir -r requirements_test.txt
- name: Download all models
run: |
python3 -c "from carvekit.ml.files.models_loc import download_all; download_all();"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest -s -v
25 changes: 25 additions & 0 deletions .github/workflows/master_docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test Docker CPU CI/CD

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the CPU Docker img
run: docker build . --file Dockerfile.cpu --tag carvekit
- name: Test CPU Docker image
run: docker run --rm carvekit pytest
- name: Build the GPU Docker image
run: docker build . --file Dockerfile.cuda --tag carvekit_gpu
- name: Test GPU Docker image on CPU
run: docker run --rm carvekit_gpu pytest

26 changes: 0 additions & 26 deletions .github/workflows/test_lastest_branch.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/test_master_branch.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
__pycache__
/tests/.pytest_cache/
/tests/tests_temp/
/carvekit/ml/files/checkpoints/basnet/basnet.pth
/carvekit/ml/files/checkpoints/u2net/full_weights.pth
/carvekit/ml/files/checkpoints/deeplab/deeplab.pth
/carvekit/ml/files/checkpoints/fba_matting/fba_matting.pth
/.pytest_cache/
/carvekit.egg-info/
54 changes: 54 additions & 0 deletions Dockerfile.cpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM python:3.8.2 as builder
WORKDIR /app

# Models download stage
RUN pip3 install --no-cache-dir tqdm requests
RUN mkdir -p ./carvekit/utils/
RUN mkdir -p ./carvekit/ml/files
RUN touch ./carvekit/__init__.py
RUN touch ./carvekit/ml/__init__.py
RUN touch ./carvekit/utils/__init__.py
COPY ./carvekit/utils/download_models.py ./carvekit/utils/download_models.py
COPY ./carvekit/ml/files/__init__.py ./carvekit/ml/files/__init__.py
COPY ./carvekit/ml/files/models_loc.py ./carvekit/ml/files/models_loc.py
RUN python3 -c "from carvekit.ml.files.models_loc import download_all; download_all();"
RUN rm -rf ./carvekit

FROM python:3.8.2
WORKDIR /app

RUN apt-get update && apt-get -y install libgl1 # Install cv2 dep.
COPY --from=builder /root/.carvekit /root/.carvekit

# Install requirements
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
COPY requirements_test.txt ./
RUN pip3 install --no-cache-dir -r requirements_test.txt

# Update code
COPY ./ ./

# Install to site-packages to make possible run tests and process images by cli
RUN pip3 install -e ./

ENV CARVEKIT_PORT '5000'
ENV CARVEKIT_HOST '0.0.0.0'
ENV CARVEKIT_SEGMENTATION_NETWORK 'u2net'
ENV CARVEKIT_PREPROCESSING_METHOD 'none'
ENV CARVEKIT_POSTPROCESSING_METHOD 'fba'
ENV CARVEKIT_DEVICE 'cpu'
ENV CARVEKIT_BATCH_SIZE_SEG '5'
ENV CARVEKIT_BATCH_SIZE_MATTING '1'
ENV CARVEKIT_SEG_MASK_SIZE '320'
ENV CARVEKIT_MATTING_MASK_SIZE '2048'
ENV CARVEKIT_AUTH_ENABLE '1'

# Tokens will be generated automatically every time the container is restarted if ENV is not set.

# ENV CARVEKIT_ADMIN_TOKEN 'admin_token' # Do not use this env when creating an image as it is not safe.
# ENV CARVEKIT_ALLOWED_TOKENS 'test_token1,test_token2' # Do not use this env when creating an image as it is not safe.

EXPOSE 5000

CMD ["/bin/sh", "-c", "uvicorn carvekit.web.app:app --host $CARVEKIT_HOST --port $CARVEKIT_PORT"]
54 changes: 54 additions & 0 deletions Dockerfile.cuda
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM python:3.8.2 as builder
WORKDIR /app

# Models download stage
RUN pip3 install --no-cache-dir tqdm requests
RUN mkdir -p ./carvekit/utils/
RUN mkdir -p ./carvekit/ml/files
RUN touch ./carvekit/__init__.py
RUN touch ./carvekit/ml/__init__.py
RUN touch ./carvekit/utils/__init__.py
COPY ./carvekit/utils/download_models.py ./carvekit/utils/download_models.py
COPY ./carvekit/ml/files/__init__.py ./carvekit/ml/files/__init__.py
COPY ./carvekit/ml/files/models_loc.py ./carvekit/ml/files/models_loc.py
RUN python3 -c "from carvekit.ml.files.models_loc import download_all; download_all();"
RUN rm -rf ./carvekit

FROM pytorch/pytorch:1.10.0-cuda11.3-cudnn8-runtime
WORKDIR /app

RUN apt-get update && apt-get -y install libgl1 libglib2.0-0 # Install cv2 dep.
COPY --from=builder /root/.carvekit /root/.carvekit

# Install requirements
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu113
COPY requirements_test.txt ./
RUN pip3 install --no-cache-dir -r requirements_test.txt

# Update code
COPY ./ ./

# Install to site-packages to make possible run tests and process images by cli
RUN pip3 install -e ./

ENV CARVEKIT_PORT '5000'
ENV CARVEKIT_HOST '0.0.0.0'
ENV CARVEKIT_SEGMENTATION_NETWORK 'u2net'
ENV CARVEKIT_PREPROCESSING_METHOD 'none'
ENV CARVEKIT_POSTPROCESSING_METHOD 'fba'
ENV CARVEKIT_DEVICE 'cuda'
ENV CARVEKIT_BATCH_SIZE_SEG '5'
ENV CARVEKIT_BATCH_SIZE_MATTING '1'
ENV CARVEKIT_SEG_MASK_SIZE '320'
ENV CARVEKIT_MATTING_MASK_SIZE '2048'
ENV CARVEKIT_AUTH_ENABLE '1'

# Tokens will be generated automatically every time the container is restarted if ENV is not set.

# ENV CARVEKIT_ADMIN_TOKEN 'admin_token' # Do not use this env when creating an image as it is not safe.
# ENV CARVEKIT_ALLOWED_TOKENS 'test_token1,test_token2' # Do not use this env when creating an image as it is not safe.

EXPOSE 5000

CMD ["/bin/sh", "-c", "uvicorn carvekit.web.app:app --host $CARVEKIT_HOST --port $CARVEKIT_PORT"]
Loading

0 comments on commit e3f1374

Please sign in to comment.