Package: img2feat
It is an image feature extractor based on a convolutional neural
network.GithubPyPIInstallation% pip install img2featRequired libraries: numpy, torch, torchvision, opencv-pythonclassCNNThe CNN converts a list of numpy images to features, where numpy image
is assumed opencv format, or [Height, Width, BGR]. The shape of the
output features is [ length of the list of the input images,dim_featureof the CNN].Available networks: alexnet, vgg11, vgg13, vgg16, vgg19, resnet18,
resnet34, resnet101, resnet152, densenet121, densenet161, densenet169,
densenet201 googlenet, mobilenetfromimg2featimportCNNnet=CNN('vgg11')x=net([img])Methodsavailable_networks() -> list of stringReturn the list of names of available networks.init( network=‘vgg11’, gpu=False, img_size=(224,224) )Constructornetworkshould be one ofavailable_networks()gpuis set True, if the GPU is available.img_sizeis the image size which is input to the network, (width,
height)call( imgs ) -> feature (numpy float32)It converts the list of images to the features.imgsis thee list of images. The image is should be the opencv
format, or [Height, Width, BGR].featureis the converted features where [ len(imgs),dim_feature].Variablesdim_feature(int)It is the dimension of the output feature.classPixelFeatureThe PixelFeature converts images to per-pixel features. The feature is
the numpy array of [Height, Width, Dim Feature].Available networks: vgg11, vgg13, vgg16, vgg19,fromimg2featimportCNNnet=CNN('vgg11')x=net([img])Methodsavailable_networks() -> list of stringReturn the list of names of available networks.init( network=‘vgg11’, gpu=False )Constructornetworkshould be one ofavailable_networks()gpuis set True, if the GPU is available.call( imgs ) -> list of feature (numpy float32)It converts the list of images to the features.imgsis thee list of images. The image is should be the opencv
format, or [Height, Width, BGR].featureis the converted features where [ height, width,dim_featute]. The height and width are same as the input image.Variablesdim_feature(int)It is the dimension of the output feature.classMirrorThe Mirror provide a data augmentation of mirroring.Methodscall( imgs ) -> augmented imagesIt return the augmented images. The output is the list of images. The
odd is the original images and the even is the mirrored images.Variablesnb_augintIt return 2.classTenCropThe TenCrop provide a typical 10-crop data augmentation. First, images
are resized so that the shorter side is a setting scale. Then, center,
top-left, top-right, bottom-left, and bottom-right are cropped.Methodsinit( scales=[224, 256, 384, 480, 640], mirror=True,
img_size=(224,224) )Constructor.scalesis a list of scales. Images are resized so that the shorter
side is scale.Ifmirroris True, the mirroring augmentation is also applied.img_sizeis cropping size.call( imgs ) -> augmented imagesIt returns the augmented images.Variablesimg_sizeIt is the cropping size. [Width, Height]nb_augIt is the number of augmentation fro a single image. It is the
multiplication of len(scales) * 5 * 2, if mirror is TruepackageantbeeIt is utility package for the dataset of ants and bees inTransfer
Learning for Computer Vision
Tutorial.Methodsload( squared=True, root=None ) -> ( Itrain, Ytrain ), ( Itest,
Ytest )rootis the root directory of the data. If it is None, the root
directory is set as the package directory.Ifsquaredis True, only squared images are loaded. Ifsquaredis
False, all images are loaded.Itrain, Itestare lists of images.Ytrain, Ytestare numpy array of the label. 0: ant, 1: bee.load_squared_npy( name, root=None ) -> ( Xtrain, Ytrain ), (
Xtest, Ytest )rootis the root directory of the data. If it is None, the root
directory is set as the package directory.nameis the name of CNN network.Xtrain, Xtestare numpy array of extracted features.Ytrain, Ytestare numpy array of the label. 0: ant, 1: bee.Variablesstrstr[0]: ‘ant’, str[1]: ‘bee’Sample Codessample1.py:
Linear regression.sample2.py:
Data augmentation.Network ReferencesAlexNet: One weird trick for parallelizing convolutional neural
networksVGG: Very Deep Convolutional Networks for Large-Scale Image
RecognitionResNet: Deep Residual Learning for Image
RecognitionDenseNet: Densely Connected Convolutional
NetworksMobileNet: Inverted Residuals and Linear
BottlenecksGoogLeNet: Going Deeper with
Convolutions