Skip to content

Commit b921943

Browse files
committed
transformer workflow implemented
1 parent 1beefe7 commit b921943

Some content is hidden

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

42 files changed

+57693
-562
lines changed

.appveyor.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
branches:
22
only:
33
- master
4+
- dev
45

56
environment:
67
global:
@@ -18,11 +19,15 @@ install:
1819
build_script:
1920
- cibuildwheel --output-dir dist
2021

21-
deploy_script:
22-
- python -m pip install twine
23-
# Remove for deployment to official PyPi repo
24-
- "python -m twine upload --repository-url https://test.pypi.org/legacy/ --skip-existing dist\\*.whl"
25-
2622
artifacts:
2723
- path: "dist\\*.whl"
28-
name: Wheels
24+
name: Wheels
25+
26+
for:
27+
- branches:
28+
only:
29+
- master
30+
deploy_script:
31+
- python -m pip install twine
32+
# Remove for deployment to official PyPi repo
33+
- "python -m twine upload --repository-url https://test.pypi.org/legacy/ --skip-existing dist\\*.whl"

.travis.yml

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1+
branches:
2+
only:
3+
- master
4+
- dev
15
env:
26
global:
3-
- CIBW_SKIP="cp27-* cp33-* cp34-* cp35-* *-manylinux1_i686"
4-
- CIBW_BEFORE_BUILD="python -m pip install -r requirements.txt"
5-
- TWINE_USERNAME=mabucchi
6-
- secure: JvT4s6k9r7goUhxxeSwAjPHA/EQVKwYo838a6Ze4wm/SSuG2OLYqU29NTyJnQmJmU7ksF1YT5QK5NWqEvkGTjvmpiixbnVowd4iwcmFLgbu/AG+WxVbk0WW+f1yufjY49nq8RY4VeAhl+Rt10m1blbzFjUADxXVDVir8ujQzvCUj5rikQndjc3DzJPVZKuNK5NOPfx/K9TXXTgGmCdRGoSHkKbQRCGz/H7AOgxCtsSH3dfRBGgpqhDodMjsPmgWvPntxO74N2L9I/1gH1yYEDKo+k14BkJBdKFy12dUTE1NXjTeqrN1MrrDju94qCBdH1jHn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USu9CQH7h6CBt9cU5FqFZ31S2CbwEi6AuoA/zgI64J3aUMSFiXVM6RfKm1Qo1hdaej3LbvidBRTZNVrzsYcnRBclaQTYXsYGM=
711
matrix:
812
include:
9-
- language: python
10-
dist: xenial
11-
sudo: required
12-
python: '3.7'
13-
services:
14-
- docker
15-
install:
16-
- pip install --upgrade cibuildwheel twine
17-
- touch .cibuildwheel
18-
- os: osx
19-
language: generic
20-
install:
21-
- brew upgrade python
22-
- sudo python3 -m pip install --upgrade cibuildwheel twine
23-
- touch .cibuildwheel
13+
- language: python
14+
dist: xenial
15+
sudo: required
16+
python: "3.7"
17+
services:
18+
- docker
19+
install:
20+
- pip install --upgrade cibuildwheel twine
21+
- touch .cibuildwheel
22+
- os: osx
23+
language: generic
24+
install:
25+
- brew upgrade python
26+
- sudo python3 -m pip install --upgrade cibuildwheel twine
27+
- touch .cibuildwheel
28+
2429
script:
25-
- cibuildwheel --output-dir dist
26-
- twine upload --repository-url https://test.pypi.org/legacy/ --skip-existing dist/*.whl
30+
- cibuildwheel --output-dir dist
31+
- |
32+
if [ "$TRAVIS_BRANCH" == "master" ]; then
33+
twine upload --repository-url https://test.pypi.org/legacy/ --skip-existing dist/*.whl
34+
fi

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
pybalu
2-
============
1+
# pybalu
32

43
[![Build Status](https://travis-ci.com/mbucchi/pybalu.svg?branch=master)](https://travis-ci.com/mbucchi/pybalu)
54
[![Build status](https://ci.appveyor.com/api/projects/status/f010n1dwwyf5f2rk/branch/master?svg=true)](https://ci.appveyor.com/project/mbucchi/pybalu/branch/master)
65

7-
86
Python implementation for Balu, a computer vision, pattern recognition and image processing library. Originally implemented in matlab by Domingo Mery.
97

10-
## Setup for development and testing
8+
## Installing pybalu
119

1210
Python 3.6 or higher is required to use this package. In order to install, simply run
11+
1312
```bash
1413
$ pip install --index-url https://test.pypi.org/simple/ pybalu
1514
```
1615

16+
## Development and contributing
17+
18+
If you would like to contribute:
19+
20+
- Fork the repo
21+
- Create a new branch called `feature/<feature-desc>` or `fix/<fix-desc>` depending on the nature of your contribution
22+
- Perform a pull request and wait for your contribution to be accepted or rejected
23+
24+
Possible and useful contributions:
25+
26+
- Tests
27+
- More feature extraction, analysis and transformation funcitons
28+
- Fixes
29+
- Documentation
30+
- Examples
31+
1732
## Documentation
18-
_TODO_
33+
34+
_TODO_

pybalu/IO/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

pybalu/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from . import feature_selection
66
from . import feature_transformation
77
from . import img_processing
8-
from . import IO
8+
from . import io
99
from . import misc
1010
from . import performance_eval
11-
from . import utils
1211

13-
__version__ = '0.2.0'
12+
__version__ = '0.2.1'

pybalu/base.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from sklearn.base import BaseEstimator, TransformerMixin
2+
import tqdm
3+
from sklearn.pipeline import make_pipeline
4+
5+
__all__ = ['FeatureExtractor', 'ImageProcessor']
6+
7+
8+
class FeatureExtractor(BaseEstimator, TransformerMixin):
9+
"""Base class for all feature extractors in PyBalu
10+
11+
12+
Notes (from sklearn.base.BaseEstimator)
13+
-----
14+
All estimators should specify all the parameters that can be set
15+
at the class level in their ``__init__`` as explicit keyword
16+
arguments (no ``*args`` or ``**kwargs``).
17+
"""
18+
19+
def __init__(self):
20+
self.show = False
21+
22+
def _get_iterator(self, X, *, desc=None):
23+
if self.show:
24+
if desc is not None:
25+
desc = f'Extracting Features({desc})'
26+
else:
27+
desc = 'Extracting Features'
28+
return tqdm.tqdm(X, desc=desc, total=len(X), unit_scale=True)
29+
return iter(X)
30+
31+
def fit(self, X, y=None):
32+
"""Do nothing and return the estimator unchanged
33+
This method is just there to implement the usual API and hence
34+
work in pipelines.
35+
Parameters
36+
----------
37+
X : array-like, shape [n_samples, n_features]
38+
Training data.
39+
"""
40+
return self
41+
42+
43+
class ImageProcessor(BaseEstimator, TransformerMixin):
44+
"""Base class for all image transformers in PyBalu
45+
46+
47+
Notes (from sklearn.base.BaseEstimator)
48+
-----
49+
All estimators should specify all the parameters that can be set
50+
at the class level in their ``__init__`` as explicit keyword
51+
arguments (no ``*args`` or ``**kwargs``).
52+
"""
53+
54+
def __init__(self):
55+
self.show = False
56+
57+
def _get_iterator(self, X, *, desc=None):
58+
if self.show:
59+
if desc is not None:
60+
desc = f'Processing Images({desc})'
61+
else:
62+
desc = 'Processing Images'
63+
return tqdm.tqdm(X, desc=desc, total=len(X), unit_scale=True)
64+
return iter(X)
65+
66+
def fit(self, X, y=None):
67+
"""Do nothing and return the estimator unchanged
68+
This method is just there to implement the usual API and hence
69+
work in pipelines.
70+
Parameters
71+
----------
72+
X : array-like, shape [n_samples, n_features]
73+
Training data.
74+
"""
75+
return self

pybalu/classification/_structure.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import numpy as np
44

5+
56
def structure(classifier, *, train_data=None, test_data=None, train_classes=None, initialize=True,
67
fit_method='fit', predict_method='predict', classifier_opts=None):
78
'''\
@@ -57,7 +58,9 @@ def structure(classifier, *, train_data=None, test_data=None, train_classes=None
5758
'''
5859

5960
if not hasattr(classifier, fit_method) or not hasattr(classifier, predict_method):
60-
raise ValueError("`classifier` must define methods `fit` and `predict` in order to be considered a valid classifier")
61+
raise ValueError(
62+
f"`classifier` must define methods `{fit_method}` and `{predict_method}` in order to be considered a valid classifier"
63+
)
6164

6265
classifier_opts = classifier_opts or dict()
6366

@@ -68,13 +71,15 @@ def structure(classifier, *, train_data=None, test_data=None, train_classes=None
6871

6972
if train_data is not None:
7073
if train_classes is None:
71-
raise ValueError("`train_features` given but no `classification` given to train classifier")
72-
74+
raise ValueError(
75+
"`train_features` given but no `classification` given to train classifier"
76+
)
77+
7378
classifier_instance = classifier(**classifier_opts)
7479
getattr(classifier_instance, fit_method)(train_data, train_classes)
7580

7681
if test_data is not None:
7782
prediction = getattr(classifier_instance, predict_method)(test_data)
7883
return np.array(prediction), classifier_instance
79-
80-
return np.empty(0), classifier_instance
84+
85+
return np.empty(0), classifier_instance

pybalu/feature_extraction/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from ._all import *
33
from ._basic_geo import *
44
from ._basic_int import *
5-
from ._feature_extractor import *
65
from ._flusser import *
76
from ._fourier import *
87
from ._fourier_des import *
@@ -13,4 +12,4 @@
1312
from ._hog import *
1413
from ._hugeo import *
1514
from ._huint import *
16-
from ._lbp import *
15+
from ._lbp import *

pybalu/feature_extraction/_all.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
__all__ = ['all']
1+
import numpy as np
2+
from pybalu.base import FeatureExtractor
3+
__all__ = ['all', 'AllExtractor']
4+
25

36
def all(image):
4-
return image.flatten()
7+
return image.flatten()
8+
9+
10+
class AllExtractor(FeatureExtractor):
11+
def transform(self, X):
12+
return np.array([all(x) for x in self._get_iterator(X)])

0 commit comments

Comments
 (0)