Skip to main content

wbia_orientation - A plug-in for detecting the orientation of various species in images for WBIA system

Project description

Build and upload to PyPI (main) Latest PyPI version Documentation on ReadTheDocs

Orientation Plug-in - Part of the WildMe / Wildbook IA Project.

A plugin for automatic detection of object-oriented bounding box based on axis-aligned box for wildlife species.

Installation

./run_developer_setup.sh

REST API

With the plugin installed, register the module name with the WBIAControl.py file in the wbia repository located at wbia/wbia/control/WBIAControl.py. Register the module by adding the string wbia_plugin_orientation to the list AUTOLOAD_PLUGIN_MODNAMES.

Then, load the web-based WBIA IA service and open the URL that is registered with the @register_api decorator.

cd ~/code/wbia/
python dev.py --web
{"status": {"cache": -1, "message": "", "code": 200, "success": true}, "response": "[wbia_plugin_identification_example] hello world with WBIA controller <WBIAController(testdb1) at 0x11e776e90>"}

Python API

python
>>> import wbia
>>> import wbia_orientation
>>> species = 'spotteddolphin'
>>> url = 'https://cthulhu.dyn.wildme.io/public/datasets/orientation.spotteddolphin.coco.tar.gz'
>>> ibs = wbia_orientation._plugin.wbia_orientation_test_ibs(species, dataset_url=url)
>>> aid_list = ibs.get_valid_aids()
>>> aid_list = aid_list[:10]
>>> output, theta = ibs.wbia_plugin_detect_oriented_box(aid_list, species, False, False)
>>> expected_theta = [-0.4158303737640381, 1.5231519937515259,
                      2.0344438552856445, 1.6124389171600342,
                      1.5768203735351562, 4.669830322265625,
                      1.3162155151367188, 1.2578175067901611,
                      0.9936041831970215,  0.8561460971832275]
>>> import numpy as np
>>> diff = np.abs(np.array(theta) - np.array(expected_theta))
>>> assert diff.all() < 1e-6

The function from the plugin is automatically added as a method to the ibs object as ibs.wbia_plugin_detect_oriented_box(), which is registered using the @register_ibs_method decorator.

Code Style and Development Guidelines

Contributing

It’s recommended that you use pre-commit to ensure linting procedures are run on any commit you make. (See also pre-commit.com)

Reference pre-commit’s installation instructions for software installation on your OS/platform. After you have the software installed, run pre-commit install on the command line. Now every time you commit to this project’s code base the linter procedures will automatically run over the changed files. To run pre-commit on files preemtively from the command line use:

git add .
pre-commit run

# or

pre-commit run --all-files

Brunette

Our code base has been formatted by Brunette, which is a fork and more configurable version of Black (https://black.readthedocs.io/en/stable/).

Flake8

Try to conform to PEP8. You should set up your preferred editor to use flake8 as its Python linter, but pre-commit will ensure compliance before a git commit is completed.

To run flake8 from the command line use:

flake8

This will use the flake8 configuration within setup.cfg, which ignores several errors and stylistic considerations. See the setup.cfg file for a full and accurate listing of stylistic codes to ignore.

PyTest

Our code uses Google-style documentation tests (doctests) that uses pytest and xdoctest to enable full support. To run the tests from the command line use:

pytest

To run doctests with +REQUIRES(–web-tests) do:

pytest --web-tests

Results and Examples

Quantitative and qualitative results are presented here

Implementation details

Dependencies

  • Python >= 3.7

  • PyTorch >= 1.5

Data

Data used for training and evaluation:

Data preprocessing

Each dataset is preprocessed to speed-up image loading during training. At the first time of running a training or a testing script on a dataset the following operations are applied:
  • an object is cropped based on a segmentation boudnding box from annotations with a padding around equal to the half size of the box to allow for image augmentations

  • an image is resized so the smaller side is equal to the double size of a model input; the aspect ratio is preserved.

The preprocessed dataset is saved in data directory.

Data augmentations

During the training the data is augmented online in the following way:

  • Random Horizontal Flips

  • Random Vertical Flips

  • Random Rotations

  • Random Scale

  • Random Crop

  • Color Jitter (variations in brightness, hue, contrast and saturation)

Both training and testing data are resized to the model input size and normalized.

Training

Run the training script:

python wbia_orientation/train.py --cfg <path_to_config_file> <additional_optional_params>

Configuration files are listed in experiments folder. For example, the following line trains the model with parameters specified in the config file:

python wbia_orientation/train.py --cfg wbia_orientation/config/mantaray.yaml

To override a parameter in config, add this parameter as a command line argument:

python wbia_orientation/train.py --cfg wbia_orientation/config/mantaray.yaml TRAIN.BS 64

Testing

The test script evaluates on the test set with the best model saved during training:

python wbia_orientation/test.py --cfg <path_to_config_file> <additional_optional_params>

For example:

python wbia_orientation/test.py --cfg wbia_orientation/config/mantaray.yaml

By default, the accuracy of detected rotation angle is computed for a threshold of 10 degrees. Pass a different value as a command line parameter to evaluate with another threshold:

python wbia_orientation/test.py --cfg wbia_orientation/config/mantaray.yaml TEST.THETA_THR 15.
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wbia-orientation-4.0.1.tar.gz (6.4 MB view details)

Uploaded Source

Built Distribution

wbia_orientation-4.0.1-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file wbia-orientation-4.0.1.tar.gz.

File metadata

  • Download URL: wbia-orientation-4.0.1.tar.gz
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wbia-orientation-4.0.1.tar.gz
Algorithm Hash digest
SHA256 5ce0e9a95b88e760501cc318e501969cc4f9c97481a0d6c29b01ebf4c8566d19
MD5 654cb463d8c3b532cf04fe7425992989
BLAKE2b-256 b82670f702f0165f08384a56e63692fca1cc640d90040b1f6860b4c28b621dd4

See more details on using hashes here.

File details

Details for the file wbia_orientation-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: wbia_orientation-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wbia_orientation-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8f37d2b26bb36c4e0239e12e2e877384f0a2466d786f635db6f6cd0a8bfd0fa
MD5 456ac32d8b0ba857b523a9e0a8830f86
BLAKE2b-256 3a8d11ea7eab3a7653304ca57c617d90f7cca433cc9303031ccf19d4de85b940

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page