Skip to content

Commit

Permalink
Merge pull request #28 from Xu-Justin/initial_release
Browse files Browse the repository at this point in the history
Initial release (0.1.0)
  • Loading branch information
Xu-Justin authored Dec 5, 2022
2 parents e6dae97 + eb510a4 commit 7668a18
Show file tree
Hide file tree
Showing 222 changed files with 8,596 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
omit =
*/site-packages/*
*/dist-packages/*
*/distutils/*
tests/*
patchmentation/dataset.py

disable_warnings = couldnt-parse
32 changes: 32 additions & 0 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: docker ci

on:
push:
branches:
- '**docker**'
pull_request:
branches:
- '**'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: jstnxu/patchmentation:env
42 changes: 42 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
requirements=requirements/requirements-main.txt
if [ -f $requirements ]; then pip install -r $requirements; fi
- 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: Run test
run: |
pytest -v
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*__pycache__*
.pytest_cache/*

.coverage
htmlcov/*

# development tools
dev.ipynb
.ipynb_checkpoints

# deployment
build/*
dist/*
*.egg-info/
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.10.8-slim-bullseye

RUN apt-get update -qq && \
apt-get install -y zip unzip htop screen libgl1-mesa-glx libglib2.0-0 libsm6 libxrender1 libxext6 && \
rm -rf /var/cache/apk/*

COPY requirements/* /requirements/
RUN pip --no-cache-dir install -r /requirements/requirements-main.txt
RUN pip --no-cache-dir install -r /requirements/requirements-test.txt
RUN pip --no-cache-dir install -r /requirements/requirements-dev.txt
RUN pip --no-cache-dir install -r /requirements/requirements-streamlit.txt

WORKDIR /workspace
CMD ["bash"]
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# patchmentation
# patchmentation

A python library to perform patch augmentation.

## Installation

```bash
pip install patchmentation
```

THIS README will be updated soon.
2 changes: 2 additions & 0 deletions Streamlit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import section
from . import page
30 changes: 30 additions & 0 deletions Streamlit/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os, sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import page

import streamlit as st
from streamlit_option_menu import option_menu

def main():
MENU_DATASET = 'Dataset'
MENU_PATCHMENTATION = 'Patchmentation'

with st.sidebar:
menu = option_menu(
'Main Menu',
[
MENU_DATASET,
MENU_PATCHMENTATION
],
default_index=0
)

if menu == MENU_DATASET:
page.dataset()

if menu == MENU_PATCHMENTATION:
page.patchmentation()

if __name__ == '__main__':
main()
36 changes: 36 additions & 0 deletions Streamlit/page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os, sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import section
from patchmentation import patch_augmentation

import streamlit as st
import random

def dataset(key: str = 'page-dataset'):
dataset = section.dataset(key=f'{key}-dataset')
section.display_dataset(dataset, key=f'{key}-display_dataset')

def patchmentation(key: str = 'page-patchmentation'):
dataset = section.dataset(key=f'{key}-dataset')
shuffle = section.input_shuffle(key=f'{key}-shuffle')
negative_patches = section.negative_patch(dataset, key=f'{key}-negative-patches')
background_image = section.background_image(key=f'{key}-background_image')
actions = section.input_actions(key=f'{key}-input_actions')
conf = section.patchmentation_configuration(key=f'{key}-patchmentation_conf')

if dataset is None:
st.error(f'ERROR: Invalid dataset')
return

patches = negative_patches
for image_patch in dataset.image_patches:
for patch in image_patch.patches:
patches.append(patch)

if shuffle:
random.shuffle(patches)

result_image_patch = patch_augmentation(patches, background_image, conf.get('visibility_threshold', 0.5), actions, max_n_patches=conf.get('max_n_patches', 100))
section.display_image_patch(result_image_patch, key=f'{key}-display_result_image_patch')
section.refresh_button(key=f'{key}-refresh')
Loading

0 comments on commit 7668a18

Please sign in to comment.