Skip to content

Commit

Permalink
Merge pull request #7 from JonatanRasmussen/pytest
Browse files Browse the repository at this point in the history
added unit tests and coverage reports to project
  • Loading branch information
1p0d authored Jan 15, 2024
2 parents f681747 + aa78545 commit 8e075a8
Show file tree
Hide file tree
Showing 63 changed files with 141 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
omit =
*__init__*
*/tests/*
34 changes: 34 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Python application
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
coverage run -m pytest tests/
coverage html --title="DTU 02476 Group 100 Project Coverage Report"
- name: Upload pytest test results
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: htmlcov/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion project_winegrape_src_files/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from project_winegrape_src_files.models.model import MyNeuralNet
from project_winegrape_src_files.models.model import ImageClassifier
from project_winegrape_src_files.predict_model import predict
26 changes: 26 additions & 0 deletions project_winegrape_src_files/conf/test_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
reproducibility:
seed: 123

data:
dir: "tests/test_data/raw/grapevine-leaves-image-dataset/Grapevine_Leaves_Image_Dataset"
transform_level: "light"
batch_size: 32
val_split: 0.2

model:
model_name: "efficientnet_b0" # or resnetv2_50t
num_classes: 5
drop_rate: 0.3
pretrained: true

optimization:
lr_pretrained: 1e-5
lr_final: 1e-4
optimizer: "AdamW"
criterion: "cross_entropy"

training:
max_epochs: 40

logging:
log_every_n_steps: 40
2 changes: 1 addition & 1 deletion project_winegrape_src_files/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
num_workers = 0
):
super().__init__()
self.root_dir = Path(os.getcwd(), data_dir)
self.root_dir = Path(data_dir)
self.transform_level = transform_level
self.img_size = img_size
self.batch_size = batch_size
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "project_winegrape_src_files"
version = "0.0.1"
description = "Your project description"
description = ""
authors = [
{ name = "Your Name", email = "[email protected]" },
]
Expand Down
25 changes: 16 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
torch >= 2.1.0
timm >= 0.9.12
pytorch-lightning >= 2.1.3
torchvision >= 0.16.0
torchmetrics >= 1.2.1
numpy >= 1.26.0
opendatasets >= 0.1.22
hydra-core >= 1.3.2
omegaconf >= 2.3.0
click==8.1.7
coverage==7.4.0
dvc==3.39.0
dvc-gdrive==3.0.1
hydra-core==1.3.2
kaggle==1.6.2
Markdown==3.5.2
numpy==1.26.3
omegaconf==2.3.0
opendatasets==0.1.22
pytest==7.4.4
pytorch_lightning==2.1.3
timm==0.9.12
torch==2.1.2
torchmetrics==1.3.0
torchvision==0.16.2
14 changes: 0 additions & 14 deletions requirements_dev.txt

This file was deleted.

Empty file added tests/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from hydra import initialize, compose
import os

def test_config() -> None:
with initialize(version_base=None, config_path="../project_winegrape_src_files/conf"):
test_cfg = compose(config_name="test_config")
# assert top level keys
assert "reproducibility" in test_cfg.keys()
assert "data" in test_cfg.keys()
assert "model" in test_cfg.keys()
assert "optimization" in test_cfg.keys()
assert "training" in test_cfg.keys()
assert "logging" in test_cfg.keys()
# assert data exists
assert os.path.exists(os.path.dirname(test_cfg.data.dir))
19 changes: 19 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from project_winegrape_src_files.data.data import DataModule
from hydra import initialize, compose

def test_data():
with initialize(version_base=None, config_path="../project_winegrape_src_files/conf"):
test_cfg = compose(config_name="test_config")
data_module = DataModule(
data_dir=test_cfg.data.dir,
transform_level=test_cfg.data.transform_level,
batch_size=test_cfg.data.batch_size,
val_split=test_cfg.data.val_split,
)
data_module.setup()
training_dataset = data_module.train_dataloader()
val_dataset = data_module.val_dataloader()
test_dataset = data_module.test_dataloader()
assert len(training_dataset) == 2
assert len(val_dataset) == 1
assert len(test_dataset) == 1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DATASET: https://www.muratkoklu.com/datasets/

KOKLU Murat (a), UNLERSEN M. Fahri (b), OZKAN Ilker Ali (a), ASLAN M. Fatih(c), SABANCI Kadir (c)

(a) Department of Computer Engineering, Selcuk University, Turkey, Konya, Turkey
(b) Department of Electrical and Electronics Engineering, Necmettin Erbakan University, Konya, Turkey
(c) Department of Electrical-Electronic Engineering, Karamanoglu Mehmetbey University, Karaman, Turkey

Citation Request :
Koklu, M., Unlersen, M. F., Ozkan, I. A., Aslan, M. F., & Sabanci, K. (2022). A CNN-SVM study based on selected deep features for grapevine leaves classification. Measurement, 188, 110425. Doi:https://doi.org/10.1016/j.measurement.2021.110425

Link: https://doi.org/10.1016/j.measurement.2021.110425

DATASET: https://www.muratkoklu.com/datasets/

Highlights
• Classification of five classes of grapevine leaves by MobileNetv2 CNN Model.
• Classification of features using SVMs with different kernel functions.
• Implementing a feature selection algorithm for high classification percentage.
• Classification with highest accuracy using CNN-SVM Cubic model.

Abstract: The main product of grapevines is grapes that are consumed fresh or processed. In addition, grapevine leaves are harvested once a year as a by-product. The species of grapevine leaves are important in terms of price and taste. In this study, deep learning-based classification is conducted by using images of grapevine leaves. For this purpose, images of 500 vine leaves belonging to 5 species were taken with a special self-illuminating system. Later, this number was increased to 2500 with data augmentation methods. The classification was conducted with a state-of-art CNN model fine-tuned MobileNetv2. As the second approach, features were extracted from pre-trained MobileNetv2′s Logits layer and classification was made using various SVM kernels. As the third approach, 1000 features extracted from MobileNetv2′s Logits layer were selected by the Chi-Squares method and reduced to 250. Then, classification was made with various SVM kernels using the selected features. The most successful method was obtained by extracting features from the Logits layer and reducing the feature with the Chi-Squares method. The most successful SVM kernel was Cubic. The classification success of the system has been determined as 97.60%. It was observed that feature selection increased the classification success although the number of features used in classification decreased.

Keywords: Deep learningTransfer learningSVMGrapevine leavesLeaf identification

0 comments on commit 8e075a8

Please sign in to comment.