-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
709 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: AgriNet CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
|
||
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
|
||
jobs: | ||
runtests: | ||
name: pip | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: python -m unittest discover -q agrinet/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# AgriNet | ||
|
||
[![AgriNet CI](https://github.com/ULAS-HiPR/AI-utils/actions/workflows/agrinet.yml/badge.svg)](https://github.com/ULAS-HiPR/AI-utils/actions/workflows/agrinet.yml) | ||
|
||
A RGB to NIR image translation model for agricultural aerial evaluation on vegetation and moisture data. | ||
|
||
## Datasets | ||
|
||
nirscene0 - 477 images | ||
multiple scenes ranging in conditions, this was used as it is a good balance for generalisation. | ||
|
||
## Tools | ||
|
||
### Training | ||
|
||
CLI tool available via `python train.py --help` for more information. | ||
|
||
```man | ||
usage: train.py [-h] --name NAME --data_dir DATA_DIR --batch_size BATCH_SIZE | ||
--epochs EPOCHS [--lr LR] [--ext EXT] [--seed SEED] | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
--name NAME Name of experiment, used for logging and saving | ||
checkpoints and weights in one directory | ||
--data_dir DATA_DIR Path to data directory. must contain train and test | ||
folders with images (see --ext) | ||
--batch_size BATCH_SIZE | ||
Batch size for training | ||
--epochs EPOCHS Number of epochs to train | ||
--lr LR Learning rate for training | ||
--ext EXT Extension of the images | ||
--seed SEED Random seed for training | ||
``` | ||
|
||
### Tensorboard | ||
|
||
For monitoring loss during training and viewing input and output space | ||
|
||
```bash | ||
agrinet $ tensorboard --logdir={NAME}/logs | ||
``` | ||
|
||
**Example view** | ||
|
||
![TB example view](../assets/image.png) | ||
|
||
### Unit tests | ||
|
||
```bash | ||
agrinet $ python -m unittest discover -q tests | ||
``` |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import sys | ||
import os | ||
|
||
# fixes "ModuleNotFoundError: No module named 'utils'" | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | ||
|
||
# flake8: noqa | ||
import unittest | ||
import tensorflow as tf | ||
from utils.DataLoader import load_image_test, load_image_train, resize | ||
|
||
|
||
class TestImageDataFunctions(unittest.TestCase): | ||
def setUp(self): | ||
# Set up any necessary resources or configurations for tests | ||
pass | ||
|
||
def tearDown(self): | ||
# Clean up after tests | ||
pass | ||
|
||
def test_load_image_train(self): | ||
# Condition: input_image.shape != real_image.shape from the train dataset | ||
image_file = "assets/green-field.jpg" | ||
input_image, real_image = load_image_train(image_file) | ||
|
||
self.assertIsInstance(input_image, tf.Tensor) | ||
self.assertIsInstance(real_image, tf.Tensor) | ||
self.assertEqual(input_image.shape, real_image.shape) | ||
self.assertEqual(input_image.shape, (256, 256, 3)) | ||
|
||
def test_load_image_test(self): | ||
# Condition: input_image.shape == real_image.shape from the test dataset | ||
image_file = "assets/green-field.jpg" | ||
|
||
input_image, real_image = load_image_test(image_file) | ||
|
||
self.assertIsInstance(input_image, tf.Tensor) | ||
self.assertIsInstance(real_image, tf.Tensor) | ||
self.assertEqual(input_image.shape, real_image.shape) | ||
self.assertEqual(input_image.shape, (256, 256, 3)) | ||
|
||
def test_resize(self): | ||
# Condition: input_image.shape == real_image.shape | ||
input_image = tf.constant([[[1, 2, 3], [4, 5, 6]]], dtype=tf.float32) | ||
real_image = tf.constant([[[7, 8, 9], [10, 11, 12]]], dtype=tf.float32) | ||
height, width = 128, 128 | ||
resized_input, resized_real = resize(input_image, real_image, height, width) | ||
|
||
self.assertIsInstance(resized_input, tf.Tensor) | ||
self.assertIsInstance(resized_real, tf.Tensor) | ||
self.assertEqual(resized_input.shape, resized_real.shape) | ||
self.assertEqual(resized_input.shape, (128, 128, 3)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
import os | ||
|
||
# fixes "ModuleNotFoundError: No module named 'utils'" | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | ||
|
||
# flake8: noqa | ||
import unittest | ||
from io import StringIO | ||
from unittest.mock import patch | ||
from utils.LogManager import LogManager | ||
|
||
|
||
class TestLogManager(unittest.TestCase): | ||
def setUp(self): | ||
# Redirect stdout to capture log messages | ||
self.mock_stdout = StringIO() | ||
patch("sys.stdout", self.mock_stdout).start() | ||
|
||
def tearDown(self): | ||
# Clean up and restore stdout | ||
patch.stopall() | ||
|
||
def test_singleton_instance(self): | ||
with self.assertRaises(Exception) as context: | ||
log_manager1 = LogManager() | ||
log_manager2 = LogManager() | ||
del log_manager1, log_manager2 | ||
|
||
self.assertEqual(str(context.exception), "This class is a singleton!") | ||
|
||
def test_get_logger(self): | ||
log_manager = LogManager() | ||
logger = log_manager.get_logger("test_logger") | ||
self.assertEqual(logger.name, "utils.LogManager") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.