Featurize images using a decapitated, pre-trained deep learning network
Featurize images using a small, contained pre-trained deep learning network
- Free software: BSD license
This is the prototype for image features engineering. Supports Python 2.7, 3.4, 3.5, 3.6, and 3.7
pic2vec is a python package that performs automated feature extraction
for image data. It supports feature engineering on new image data, and allows
traditional machine learning algorithms (such as tree-based algorithms) to
train on image data.
pic2vec works on image data represented as either:
- A directory of image files.
- As URL pointers contained in a CSV.
- Or as a directory of images with a CSV containing pointers to the image files.
If no CSV is provided with the directory, it automatically generates a CSV to store the features with the appropriate images.
Each row of the CSV represents a different image, and image rows can also have columns containing other data about the images as well. Each image's featurized representation will be appended as a series of new columns at the end of the appropriate image row.
The goal of this project was to make the featurizer as easy to use and hard to break as possible. If working properly, it should be resistant to badly-formatted data, such as missing rows or columns in the csv, image mismatches between a CSV and an image directory, and invalid image formats.
However, for the featurizer to function optimally, it prefers certain constraints:
The CSV should have no missing columns or rows, and there should be full overlap between images in the CSV and the image directory
If checking predictions on a separate test set (such as on Kaggle), the filesystem needs to sort filepaths consistently with the sorting of the test set labels. The order in the CSV (whether generated automatically or passed in) will be considered the canonical order for the feature vectors.
The featurizer can only process .png, .jpeg, or .bmp image files. Any other images will be left out of the featurization by being represented by zero vectors in the image batch.
The following Python code shows a typical usage of
from pic2vec import ImageFeaturizer image_column_name = 'images' my_csv = 'path/to/data.csv' my_image_directory = 'path/to/image/directory/' my_featurizer = ImageFeaturizer(model='xception', depth=2, autosample=True) featurized_df = my_featurizer.featurize(image_column_name, csv_path=my_csv, image_path=my_image_directory)
To get started, see the following example:
- Cats vs. Dogs: Dataset from combined directory + CSV
Examples coming soon: 2. Hot Dog, Not Hot Dog: Dataset from a CSV with URLs and no image directory
See the Installation Guide for details.
If you run into trouble installing Keras or Tensorflow as a dependency, read the Keras installation guide and Tensorflow installation guide for details about installing Keras/Tensorflow on your machine.
Using Featurizer Output With DataRobot
pic2vec generates a flat CSV which is ready for supervised modeling, if the data has been labelled with a variable that
can be used as a target. The images are transformed into a set of regular columns containing numeric data.
Additionally, if unlabelled, it can be used for unsupervised learning (such as anomaly detection).
To run the unit tests with
- Limited Keras version to pre-2.3.0 to fix issues from Keras' breaking changes
- Updated version of Trafaret to a non-beta version
- Updated keras to 2.2.3 or greater
- This library upgrade changes prediction consistency across past versions of pic2vec. ResNet50 is the model that has changed the most, due to changes in implementation. Other models have small floating point changes, but still pass np.testing.assert_allclose tests.
- Updated version of Pillow to 5.4.1, in order to support Python 3.7
- Updated the README
- Added test coverage and increased error checking
- Changed default csv name
- Updated examples
- Updated version of scipy to 1.1 and numpy to 1.15
- Updated the notebook example
- Some code cleanup
- Lots of code cleanup
- Changed new_csv_name argument to new_csv_path everywhere for consistency
- Removed '_full' from the saved csv_name for the full dataframe. Features-only csv still has '_features_only' in csv name.
- Added 'featurized' to saved csv names
- Removed new_csv_path as argument to functions that do not actually require it
- Added batch processing
- Made pic2vec more programmatic (removed automatic csv-writing, etc.)
- Bound keras to <2.1.5 to remove resnet problem
- Fixed Keras backwards compatibility issues (include_top deprecated, require_flatten added)
- Fixed ResNet50 update issues (removed a zero-padding layer, updated weights)
- Updated trafaret requirement for PyPi package
- Updated cats vs. dogs example
- Fixed bugs with robust naming
- Added error message for failed image conversion
- Added robust naming options to the generated csv files
- Fixed PIL truncated image bug
- Fixed bug with CSV badly formed URLs
- Fixed mistake with InceptionV3 preprocessing happening for every model
- Added Travis and Coveralls for testing and coverage automation
- Repo went public
- Python 3.x compatibility
- Fixed image format recognition.
- Directory-only now natural sorted.
- Added multi-column support
- Added missing image column to csv
- Renamed to pic2vec
- Tests parametrized
- Second round of code review- optimized code, better type checking with trafaret
- Improved README test examples
- Fixed documentation
- Added ability to call multiple models, and packaged in SqueezeNet with weights.
- Created installation instructions and readme files, ready for prototype distribution
- Fixed import problem that prevented generated csvs from saving
- Fixed variable name bugs
- Changed image_directory_path to the more manageable image_path
- Made testing module and preprocessing module slightly more robust.
- Added features-only csv test, and got rid of the column headers in the file
- Added Documentation to data featurization modeules
- 100% test coverage
- Fixed a problem where a combined directory + csv was appending to the wrong rows when there was a mismatch between the directory and the csv.
- Fixed more bugs in build_featurizer
- Fixed build_featurizer troubles with building new csv paths in current directory
- Full requirements for keras imported
- Bug fixes
- Second release on PyPI.
- Install keras with tensorflow backend specifically
- First release on PyPI.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pic2vec-0.101.1-py2.py3-none-any.whl (4.6 MB)||File type Wheel||Python version py2.py3||Upload date||Hashes View|
|Filename, size pic2vec-0.101.1.tar.gz (7.8 MB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for pic2vec-0.101.1-py2.py3-none-any.whl