module hackathon.image_knn
#
Short summary#
module ensae_projects.hackathon.image_knn
Builds a knn classifier for image in order to find close images.
Classes#
class |
truncated documentation |
---|---|
Builds a model on the top of NearestNeighbors in order to find close images. |
Properties#
property |
truncated documentation |
---|---|
|
HTML representation of estimator. This is redundant with the logic of _repr_mimebundle_. The latter should … |
Methods#
method |
truncated documentation |
---|---|
Converts images stored in a folder into a matrix of features. |
|
Returns the associated transform function with |
|
Converts a list of images into a matrix of features. |
|
Commun private function to handle the same kind of inputs in all transform functions. |
|
Fits the model. X can be a folder. |
|
Returns images classes for the given list of indices. |
|
Returns images names for the given list of indices. |
|
See NearestNeighbors, method kneighbors. Parameter X can be a file, the image is then loaded and … |
|
See NearestNeighbors, method kneighbors_graph. Parameter X can be a file, the image is then loaded … |
|
Calls plot_gallery_images with information on the neighbors. |
|
See NearestNeighbors, method radius_neighbors. Parameter X can be a file, the image is then loaded … |
Documentation#
@file @brief Builds a knn classifier for image in order to find close images.
- class ensae_projects.hackathon.image_knn.ImageNearestNeighbors(transform='gray', image_size=(10, 10), **kwargs)#
Bases:
NearestNeighbors
Builds a model on the top of NearestNeighbors in order to find close images.
- Parameters:
transform – function which transform every image
image_size – every image is zoomed to keep the same dimension
kwargs – see NearestNeighbors
- __abstractmethods__ = frozenset({})#
- __init__(transform='gray', image_size=(10, 10), **kwargs)#
- _abc_impl = <_abc._abc_data object>#
- _folder2matrix(folder, fLOG)#
Converts images stored in a folder into a matrix of features.
- _get_transform()#
Returns the associated transform function with
self.transform_
.
- _imglist2matrix(list_of_images, fLOG)#
Converts a list of images into a matrix of features.
- _private_kn(method, X, *args, fLOG=None, **kwargs)#
Commun private function to handle the same kind of inputs in all transform functions.
@param method method to run @param X inputs, matrix, folder or list of images @param args additional positinal arguments @param fLOG logging function @param kwargs additional named arguements @return depends on method
- fit(X, y=None, fLOG=None)#
Fits the model. X can be a folder.
@param X matrix or str for a subfolder of images @param y unused @param fLOG logging function
If X is a folder, the method relies on function @see fct enumerate_image_class. In that case, the method also creates attributes:
image_names_
: all image namesimage_classes_
: subfolder the image belongs too
- get_image_classes(indices)#
Returns images classes for the given list of indices.
@param indices indices can be a single array or a matrix. @return same shape
- get_image_names(indices)#
Returns images names for the given list of indices.
@param indices indices can be a single array or a matrix. @return same shape
- kneighbors(X=None, n_neighbors=None, return_distance=True, fLOG=None)#
See NearestNeighbors, method kneighbors. Parameter X can be a file, the image is then loaded and converted with the same transform. X can also be an Image from PIL.
- kneighbors_graph(X=None, n_neighbors=None, mode='connectivity', fLOG=None)#
See NearestNeighbors, method kneighbors_graph. Parameter X can be a file, the image is then loaded and converted with the same transform. X can also be an Image from PIL.
- plot_neighbors(neighbors, distances=None, obs=None, return_figure=False, format_distance='%1.2f', folder_or_images=None)#
Calls plot_gallery_images with information on the neighbors.
- Parameters:
neighbors – matrix of indices
distances – distances to display
obs – original image, if not None, will be placed on the first row
return_figure – returns
fig, ax
instead ofax
format_distance – used to format distances
folder_or_images – image paths may be relative to some folder, in that case, they should be relative to this folder, it can also be a list of images
- Returns:
ax or fix, ax if return_figure is True
- radius_neighbors(X=None, radius=None, return_distance=True, fLOG=None)#
See NearestNeighbors, method radius_neighbors. Parameter X can be a file, the image is then loaded and converted with the same transform. X can also be an Image from PIL.
- set_fit_request(*, fLOG: bool | None | str = '$UNCHANGED$') ImageNearestNeighbors #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
pipeline.Pipeline
. Otherwise it has no effect.Parameters#
- fLOGstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
fLOG
parameter infit
.
Returns#
- selfobject
The updated object.