Img2VecResnet18

class Img2VecResnet18(reload=False)

Bases: object

Class responsible for image recognition.

device

Torch device to run neural network

getFeatureLayer()

Gets avgpool layer from resnet18 .

getSimilarImages(image: str)

Gets self.k most similar images from self.similarNames.

Parameters

image (str) – filename of image for which recommendations are desired

getSimilarityMatrix(vectors)

Create pandas DataFrame of simularities using passed vectors

Parameters

vectors (Numpy.Array) – Vectors to parse simularities

Returns

Pandas.DataFrame

getVec(img: <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/jerrytheberry-imagedatabase/envs/latest/lib/python3.7/site-packages/PIL/Image.py'>)

Converts passed image into a numpy vector

Parameters

img (Image) – pillow image to convert

Returns

Tensor as Numpy array

inputDir

Input Directory for building simularity matrix

modelName

Model to use for similarity

numberFeatures

Number of features to extract from images

updateSimilarityMatrix(k: int = 10)

Updates self.SimilarityMatrix, self.similarNames, self.similarValues and self.k using parameter k.

Parameters

k (int) – Number of recommendations to present when querrying for simularities

transformImages(inputDir=PATH_IMAGES_RAW, outputDir=PATH_IMAGES_CNN, filenames: Optional[List[str]] = None)

Process Images inside inputDir for use with neural network. Resized images are outputed to the outputDir.

*Paths are absolute