Skip to content

Commit 6623e24

Browse files
authored
Merge pull request #20 from lombokai/dev
Merge from dev to main branch
2 parents 28c91b8 + b9d347c commit 6623e24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+503
-183
lines changed

.github/workflows/dev.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "On Merge dev: Release Dev"
2+
3+
concurrency:
4+
group: dev-build-deploy-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch:
9+
push:
10+
branches:
11+
- dev
12+
13+
permissions: write-all
14+
15+
16+
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Get Latest Tag
26+
id: latest-tag
27+
run: echo "tag=$(git tag -l | sort -V | tail -1 | sed 's/-dev$//')" >> "$GITHUB_OUTPUT"
28+
29+
- name: Generate New Bumped Version
30+
uses: actions-ecosystem/action-bump-semver@v1
31+
id: bump-semver
32+
with:
33+
current_version: ${{ steps.latest-tag.outputs.tag }}
34+
level: patch
35+
36+
- name: Create Release Notes
37+
id: create-release
38+
run: |
39+
curl -f -X POST \
40+
-H "Accept: application/vnd.github.v3+json" \
41+
-H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
42+
-H "X-GitHub-Api-Version: 2022-11-28" \
43+
https://api.github.com/repos/${{ github.repository }}/releases \
44+
-d '{"tag_name":"${{ steps.bump-semver.outputs.new_version }}", "generate_release_notes":true}'

.github/workflows/main.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: "On Merge main: Release Dev"
2+
3+
concurrency:
4+
group: main-build-deploy-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch:
9+
push:
10+
branches:
11+
- main
12+
13+
permissions: write-all
14+
15+
jobs:
16+
release:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Get Latest Tag
25+
id: latest-tag
26+
run: echo "tag=$(git tag -l | sort -V | tail -1 | sed 's/-dev$//')" >> "$GITHUB_OUTPUT"
27+
28+
- name: Generate New Bumped Version
29+
uses: actions-ecosystem/action-bump-semver@v1
30+
id: bump-semver
31+
with:
32+
current_version: ${{ steps.latest-tag.outputs.tag }}
33+
level: minor
34+
35+
- name: Create Release Notes
36+
id: create-release
37+
run: |
38+
curl -f -X POST \
39+
-H "Accept: application/vnd.github.v3+json" \
40+
-H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
41+
-H "X-GitHub-Api-Version: 2022-11-28" \
42+
https://api.github.com/repos/${{ github.repository }}/releases \
43+
-d '{"tag_name":"${{ steps.bump-semver.outputs.new_version }}", "generate_release_notes":true}'

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,4 @@ cython_debug/
166166
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
167167
#.idea/
168168

169-
# data/
169+
# data/

.pre-commit-config.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: fix-byte-order-marker
6+
- id: check-yaml
7+
- id: end-of-file-fixer
8+
- id: requirements-txt-fixer
9+
- id: trailing-whitespace
10+
args: [--markdown-linebreak-ext=md]
11+
12+
- repo: https://github.com/myint/autoflake
13+
rev: v2.3.1
14+
hooks:
15+
- id: autoflake
16+
args:
17+
- --in-place
18+
- --remove-all-unused-imports
19+
- --remove-unused-variables
20+
- --ignore-init-module-imports
21+
22+
- repo: https://github.com/pycqa/flake8
23+
rev: 3.9.2 # Use the latest commit SHA or tag
24+
hooks:
25+
- id: flake8
26+
27+
- repo: https://github.com/psf/black
28+
rev: 24.4.2
29+
hooks:
30+
- id: black
31+
32+
- repo: https://github.com/pycqa/isort
33+
rev: 5.13.2
34+
hooks:
35+
- id: isort
36+
name: isort (python)
37+
38+
# - repo: https://github.com/PyCQA/bandit
39+
# rev: 1.7.5 # Update me!
40+
# hooks:
41+
# - id: bandit
42+
# args: ["--ini", "iquote/.bandit"]
43+
# # additional_dependencies: ["bandit[toml]"]
44+
45+
# - repo: https://github.com/Lucas-C/pre-commit-hooks-safety
46+
# rev: v1.3.1
47+
# hooks:
48+
# - id: python-safety-dependencies-check
49+
# # args: ["--disable-telemetry"]

Makefile

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1+
.PHONY: .venv
2+
13
run-test:
2-
PYTHONPATH=src python -m pytest -v
4+
ifdef dst
5+
PYTHONPATH=.:src python -m pytest $(dst) -v
6+
else
7+
PYTHONPATH=.:src python -m pytest -v
8+
endif
9+
10+
clear-cache:
11+
find . -type d -name '__pycache__' -exec rm -r {} + \
12+
&& find . -type f -name '*.pyc' -delete
13+
14+
run-test-cov:
15+
@PYTHONPATH=.:app:$PYTHONPATH pytest --cov=app --cov-report=xml
16+
17+
precommit:
18+
pre-commit run --all-files

README.md

+83-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
1-
# onepiece-classifier
2-
An image recognition of one piece anime character
1+
# Machine Learning Project Documentation
2+
3+
## Project Overview
4+
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.
5+
6+
## Installation Guide
7+
### Requirements
8+
It is recommended to run this application within a virtual environment. First thing first is clone the repository
9+
10+
```sh
11+
git clone https://github.com/lombokai/onepiece-classifier.git
12+
```
13+
### Virtual Environment Setup
14+
create a virtual environment
15+
16+
```sh
17+
python3 -m venv <virtual environment name>
18+
```
19+
20+
command line to activate your virtual environment in linux
21+
```sh
22+
source <virtual environment name>/bin/activate
23+
```
24+
25+
command line to activate your virtual environment in windows
26+
```sh
27+
<virtual environment name>\Scripts\activate
28+
```
29+
30+
install package requirements
31+
```sh
32+
pip install -r requirements/main.txt
33+
```
34+
35+
## Usage
36+
### Example Usage
37+
This package provide image to predict in `assets` directory. If you want to try predict an image, run predict.py script with command bellow
38+
```
39+
python3 predict.py <image path>
40+
```
41+
42+
command example if you are working in parent directory of this repo
43+
44+
```sh
45+
python3 predict.py assets/luffy.png
46+
```
47+
48+
try to predict different image with command above
49+
50+
### Run the Application
51+
install onepiece-classify package
52+
```sh
53+
pip install onepiece-classify
54+
```
55+
56+
acces predict method from onepiece-classify pakcage
57+
58+
```python
59+
from onepiece_classify.infer import ImageRecognition
60+
```
61+
62+
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
63+
64+
```python
65+
predictor = ImageRecognition(<model path>)
66+
```
67+
68+
then you just predict your image with `predict` method
69+
```python
70+
predictor.predict(<your image path>)
71+
```
72+
73+
74+
## Data Description
75+
### Data Sources
76+
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.
77+
78+
## Contributing
79+
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.
80+
81+
## License
82+
83+
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

assets/ace.png

145 KB
Loading

assets/akainu.png

70.4 KB
Loading

assets/brook.png

33.3 KB
Loading

assets/chopper.png

75.2 KB
Loading

assets/crocodile.png

354 KB
Loading

assets/franky.png

88.1 KB
Loading

assets/jinbei.png

84.3 KB
Loading

assets/kurohige.png

120 KB
Loading

assets/law.png

86.6 KB
Loading

assets/luffy.png

95.3 KB
Loading

assets/mihawk.png

624 KB
Loading

assets/nami.png

43.9 KB
Loading

assets/rayleigh.png

86.4 KB
Loading

assets/robin.png

18.5 KB
Loading

assets/sanji.png

200 KB
Loading

assets/shanks.png

446 KB
Loading

assets/usop.png

41.7 KB
Loading

assets/zoro.png

49.8 KB
Loading

predict.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
sys.path.append('src')
3+
4+
import typer
5+
from pathlib import Path
6+
from onepiece_classify.infer import ImageRecognition
7+
8+
9+
def predict_image(
10+
image_path: str = typer.Argument(help="image path", show_default=True),
11+
model_path: str = typer.Argument(None, help="path to your model (pth)", show_default=True),
12+
device: str = typer.Argument("cpu", help="use cuda if your device has cuda", show_default=True)
13+
):
14+
predictor = ImageRecognition(model_path=model_path, device=device)
15+
result = predictor.predict(image=image_path)
16+
typer.echo(f"Prediction: {result}")
17+
18+
if __name__ == "__main__":
19+
typer.run(predict_image)

requirements.txt

-10
This file was deleted.

requirements/dev.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
autoflake==2.3.1
2+
black==24.4.2
3+
isort==5.13.2
4+
5+
jupyter
6+
matplotlib
7+
pre-commit==3.7.1
8+
pytest==6.2.5
9+
pytest-pythonpath==0.7.4
10+
seaborn

requirements/main.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
numpy
2+
pandas
3+
pyarrow
4+
torch
5+
torchvision

setup.cfg

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[metadata]
2+
name = onepiece_classify
3+
version = 0.0.1
4+
author = Primary Author Name
5+
author_email = [email protected]
6+
description = A short description of the package
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
url = https://github.com/yourusername/yourproject
10+
11+
12+
[options]
13+
packages = find:
14+
python_requires = >=3.6
15+
16+
17+
[flake8]
18+
ignore = E501, F403, F401, W503
19+
max-line-length = 120
20+
exclude =
21+
.git,
22+
__pycache__,
23+
build,
24+
dist
25+
filename = ./src/onepiece_classify/*.p
26+
27+
[isort]
28+
profile = black
29+
line_length = 88
30+
lines_after_imports = 2
31+
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
32+
src_paths = src/onepiece_classify
33+
known_first_party = onepiece_classify
34+
; default_section = THIRDPARTY
35+
36+
; known_first_party = mymodule
37+
; skip = migrations, external_libs
38+
; include_trailing_comma = True
39+
; multi_line_output = 3
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .setup_data import *
1+
from .setup_data import *

0 commit comments

Comments
 (0)