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

Merge from dev to main branch #20

Merged
merged 24 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9083fe0
feat:: add dev and main workflow for release
nunenuh May 15, 2024
1873b5b
feat: update makefile with new command
nunenuh May 15, 2024
5cc8091
feat: add pre-commit to cleanup and std the code
nunenuh May 15, 2024
435a19a
feat: add separation of requirements for dev and main usage
nunenuh May 15, 2024
c777bc5
feat: add setup.cfg for example setup pyton package
nunenuh May 15, 2024
70e7601
del: delete requirements.txt
nunenuh May 15, 2024
eb86673
fix: fix the line length for isort;
nunenuh May 15, 2024
9f503a5
feat: clean the code with pre-commit
nunenuh May 15, 2024
520e957
Merge pull request #14 from lombokai/feat/repo-std
nunenuh May 15, 2024
fe72f25
add assets dir, dir to provide sample image
nurgoni May 21, 2024
d7c03b6
feat: predict.py for example usage
nurgoni May 21, 2024
00b040a
feat: update readme file
nurgoni May 21, 2024
8f254e9
feat: change sh to python #11
nurgoni May 21, 2024
6f566c6
Merge pull request #15 from lombokai/feature/readme
nurgoni May 21, 2024
8fbe6bc
fix: add device parameter and locate model and data to device #16
nurgoni May 21, 2024
351dac6
fix: add device parameter with default value cpu
nurgoni May 21, 2024
33575d0
feat: add downloader module in utils dir #18
nurgoni May 22, 2024
5988b2d
feat: edit recognition module to adopt new schema
nurgoni May 22, 2024
0897c69
feat: edit predict.py to test inference module new schema
nurgoni May 22, 2024
b98c4eb
Merge pull request #17 from lombokai/bugfix/predict
nunenuh May 22, 2024
675454e
feat: remove download parameter, change logic to auto download #18
nurgoni May 22, 2024
af7fb43
feat: edit downloader module, make it simpler
nurgoni May 22, 2024
9a1f0c5
feat: edit predict.py, keep model path for flexibility load the model…
nurgoni May 22, 2024
b9d347c
Merge pull request #19 from lombokai/feature/downloader
nunenuh May 22, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "On Merge dev: Release Dev"

concurrency:
group: dev-build-deploy-${{ github.ref }}
cancel-in-progress: true

on:
workflow_dispatch:
push:
branches:
- dev

permissions: write-all


jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get Latest Tag
id: latest-tag
run: echo "tag=$(git tag -l | sort -V | tail -1 | sed 's/-dev$//')" >> "$GITHUB_OUTPUT"

- name: Generate New Bumped Version
uses: actions-ecosystem/action-bump-semver@v1
id: bump-semver
with:
current_version: ${{ steps.latest-tag.outputs.tag }}
level: patch

- name: Create Release Notes
id: create-release
run: |
curl -f -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{"tag_name":"${{ steps.bump-semver.outputs.new_version }}", "generate_release_notes":true}'
43 changes: 43 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "On Merge main: Release Dev"

concurrency:
group: main-build-deploy-${{ github.ref }}
cancel-in-progress: true

on:
workflow_dispatch:
push:
branches:
- main

permissions: write-all

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get Latest Tag
id: latest-tag
run: echo "tag=$(git tag -l | sort -V | tail -1 | sed 's/-dev$//')" >> "$GITHUB_OUTPUT"

- name: Generate New Bumped Version
uses: actions-ecosystem/action-bump-semver@v1
id: bump-semver
with:
current_version: ${{ steps.latest-tag.outputs.tag }}
level: minor

- name: Create Release Notes
id: create-release
run: |
curl -f -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{"tag_name":"${{ steps.bump-semver.outputs.new_version }}", "generate_release_notes":true}'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# data/
# data/
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: fix-byte-order-marker
- id: check-yaml
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/myint/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --remove-unused-variables
- --ignore-init-module-imports

- repo: https://github.com/pycqa/flake8
rev: 3.9.2 # Use the latest commit SHA or tag
hooks:
- id: flake8

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)

# - repo: https://github.com/PyCQA/bandit
# rev: 1.7.5 # Update me!
# hooks:
# - id: bandit
# args: ["--ini", "iquote/.bandit"]
# # additional_dependencies: ["bandit[toml]"]

# - repo: https://github.com/Lucas-C/pre-commit-hooks-safety
# rev: v1.3.1
# hooks:
# - id: python-safety-dependencies-check
# # args: ["--disable-telemetry"]
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
.PHONY: .venv

run-test:
PYTHONPATH=src python -m pytest -v
ifdef dst
PYTHONPATH=.:src python -m pytest $(dst) -v
else
PYTHONPATH=.:src python -m pytest -v
endif

clear-cache:
find . -type d -name '__pycache__' -exec rm -r {} + \
&& find . -type f -name '*.pyc' -delete

run-test-cov:
@PYTHONPATH=.:app:$PYTHONPATH pytest --cov=app --cov-report=xml

precommit:
pre-commit run --all-files
85 changes: 83 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,83 @@
# onepiece-classifier
An image recognition of one piece anime character
# Machine Learning Project Documentation

## Project Overview
This repository contains programs for classifying images. The images used for this project are images of Onepiece anime characters. There are 18 predicted anime characters. This project is packaged in the form of a python package so that it can be used by the public.

## Installation Guide
### Requirements
It is recommended to run this application within a virtual environment. First thing first is clone the repository

```sh
git clone https://github.com/lombokai/onepiece-classifier.git
```
### Virtual Environment Setup
create a virtual environment

```sh
python3 -m venv <virtual environment name>
```

command line to activate your virtual environment in linux
```sh
source <virtual environment name>/bin/activate
```

command line to activate your virtual environment in windows
```sh
<virtual environment name>\Scripts\activate
```

install package requirements
```sh
pip install -r requirements/main.txt
```

## Usage
### Example Usage
This package provide image to predict in `assets` directory. If you want to try predict an image, run predict.py script with command bellow
```
python3 predict.py <image path>
```

command example if you are working in parent directory of this repo

```sh
python3 predict.py assets/luffy.png
```

try to predict different image with command above

### Run the Application
install onepiece-classify package
```sh
pip install onepiece-classify
```

acces predict method from onepiece-classify pakcage

```python
from onepiece_classify.infer import ImageRecognition
```

instantiate the class with your model path. Download trained model [here](https://drive.google.com/file/d/1M1-1Hs198XDD6Xx-kSWLThv1elZBzJ0j/view?usp=sharing) and make sure you specify model path parameter in the location of downloaded model

```python
predictor = ImageRecognition(<model path>)
```

then you just predict your image with `predict` method
```python
predictor.predict(<your image path>)
```


## Data Description
### Data Sources
Data obtained from Kaggle [here](https://www.kaggle.com/datasets/ibrahimserouis99/one-piece-image-classifie). The data contains a collection of 18 onepiece character images, and is saved in jpg, jpeg and png formats.

## Contributing
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

## License

[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
Binary file added assets/ace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/akainu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/brook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/chopper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/crocodile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/franky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/jinbei.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/kurohige.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/law.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/luffy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/mihawk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nami.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/rayleigh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/robin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sanji.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shanks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/zoro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
sys.path.append('src')

import typer
from pathlib import Path
from onepiece_classify.infer import ImageRecognition


def predict_image(
image_path: str = typer.Argument(help="image path", show_default=True),
model_path: str = typer.Argument(None, help="path to your model (pth)", show_default=True),
device: str = typer.Argument("cpu", help="use cuda if your device has cuda", show_default=True)
):
predictor = ImageRecognition(model_path=model_path, device=device)
result = predictor.predict(image=image_path)
typer.echo(f"Prediction: {result}")

if __name__ == "__main__":
typer.run(predict_image)
10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

10 changes: 10 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
autoflake==2.3.1
black==24.4.2
isort==5.13.2

jupyter
matplotlib
pre-commit==3.7.1
pytest==6.2.5
pytest-pythonpath==0.7.4
seaborn
5 changes: 5 additions & 0 deletions requirements/main.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
numpy
pandas
pyarrow
torch
torchvision
39 changes: 39 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[metadata]
name = onepiece_classify
version = 0.0.1
author = Primary Author Name
author_email = [email protected]
description = A short description of the package
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/yourusername/yourproject


[options]
packages = find:
python_requires = >=3.6


[flake8]
ignore = E501, F403, F401, W503
max-line-length = 120
exclude =
.git,
__pycache__,
build,
dist
filename = ./src/onepiece_classify/*.p

[isort]
profile = black
line_length = 88
lines_after_imports = 2
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
src_paths = src/onepiece_classify
known_first_party = onepiece_classify
; default_section = THIRDPARTY

; known_first_party = mymodule
; skip = migrations, external_libs
; include_trailing_comma = True
; multi_line_output = 3
2 changes: 1 addition & 1 deletion src/onepiece_classify/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .setup_data import *
from .setup_data import *
Loading
Loading