renom_img.api.classification

class VGG11 ( class_map=[] , imsize=(224 , 224) , load_pretrained_weight=False , train_whole_network=False )

VGG11 model.

Parameters:
  • class_map ( array ) – Array of class names
  • imsize ( int or tuple ) – Input image size
  • train_whole_network ( bool ) – True if the overall model is trained, otherwise False
  • load_pretrained_weight ( bool , str ) – If true, pretrained weight will be downloaded to current directory. If string is given, pretrained weight will be saved as given name.

Note

if the argument num_class is not 1000, last dense layer will be reset because the pretrained weight is trained on 1000 classification dataset.

References

Karen Simonyan, Andrew Zisserman
Very Deep Convolutional Networks for Large-Scale Image Recognition

SERIALIZED = ('imsize', 'class_map', 'num_class')
WEIGHT_URL = 'http://docs.renom.jp/downloads/weights/VGG11.h5'
build_data ( )

This function returns a function which creates input data and target data specified for VGG11.

Returns: Returns function which creates input data and target data.
Return type: (function)

Example

>>> builder = model.build_data()  # This will return function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
fit ( train_img_path_list=None , train_annotation_list=None , valid_img_path_list=None , valid_annotation_list=None , epoch=136 , batch_size=64 , augmentation=None , callback_end_epoch=None )

This function performs training with given data and hyper parameters.

Parameters:
  • train_img_path_list ( list ) – List of image path.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image path for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epoch.
  • batch_size ( int ) – Number of batch size.
  • augmentation ( Augmentation ) – Augmentation object.
  • callback_end_epoch ( function ) – Given function will be called at the end of each epoch.
Returns:

Training loss list and validation loss list.

Return type:

(tuple)

Example

>>> train_img_path_list, train_annot_list = ... # Define own data.
>>> valid_img_path_list, valid_annot_list = ...
>>> model = VGG11() # Any algorithm which provided by ReNomIMG here.
>>> model.fit(
...     # Feeds image and annotation data.
...     train_img_path_list,
...     train_annot_list,
...     valid_img_path_list,
...     valid_annot_list,
...     epoch=8,
...     batch_size=8)
>>>

Following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Number of current epoch.
  • model (Model) - Model object.
  • avg_train_loss_list (list) - List of average train loss of each epoch.
  • avg_valid_loss_list (list) - List of average valid loss of each epoch.
forward ( x )

Performs forward propagation. You can call this function using __call__ method.

Parameters: x ( ndarray , Node ) – Input to VGG11.
Returns: Returns raw output of VGG11.
Return type: (Node)

Example

>>> import numpy as np
>>> from renom_img.api.classification.vgg import VGG11
>>>
>>> x = np.random.rand(1, 3, 224, 224)
>>> class_map = ["dog", "cat"]
>>> model = VGG11(class_map)
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
get_optimizer ( current_epoch=None , total_epoch=None , current_batch=None , total_batch=None , **kwargs )

Returns an instance of Optimizer for training VGG11 algorithm. If all argument(current_epoch, total_epoch, current_batch, total_batch) are given, the learning rate is modified according to the number of training iterations or the constant learning rate is used.

Parameters:
  • current_epoch ( int ) – The number of current epoch.
  • total_epoch ( int ) – The number of total epoch.
  • current_batch ( int ) – The number of current batch.
  • total_batch ( int ) – The number of total batch.
Returns:

Optimizer object.

Return type:

(Optimizer)

loss ( x , y )

Loss function of VGG11 algorithm.

Parameters:
  • x ( ndarray , Node ) – Output of model.
  • y ( ndarray , Node ) – Target array.
Returns:

Loss between x and y.

Return type:

(Node)

Example

>>> builder = model.build_data()  # This will return function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list )

Perform prediction. Argument can be an image array, image path list or a image path.

Parameters: img_list ( ndarray , list , string ) – Image array, image path list or image path.
Returns: List of class of each image.
Return type: (list)
preprocess ( x )

Performs preprocess for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
Returns: Preprocessed data.
Return type: (ndarray)

Preprocessing for VGG is follows.

\[\begin{split}x_{red} -= 123.68 \\ x_{green} -= 116.779 \\ x_{blue} -= 103.939\end{split}\]
regularize ( )

Regularization term to a loss function.

Example

>>> x = numpu.random.rand(1, 3, 224, 224)
>>> y = numpy.random.rand(1, (5*2+20)*7*7)
>>> model = VGG11()
>>> loss = model.loss(x, y)
>>> reg_loss = loss + model.regularize() # Add weight decay term.
class VGG16 ( class_map=[] , imsize=(224 , 224) , load_pretrained_weight=False , train_whole_network=False )

VGG16 model. If the argument load_weight is True, pretrained weight will be downloaded. The pretrained weight is trained using ILSVRC2012.

Parameters:
  • class_map ( array ) – Array of class names
  • imsize ( int or tuple ) – Input image size
  • train_whole_network ( bool ) – True if the overall model is trained, otherwise False
  • load_pretrained_weight ( bool , str ) – If true, pretrained weight will be downloaded to current directory. If string is given, pretrained weight will be saved as given name.

Note

if the argument num_class is not 1000, last dense layer will be reset because the pretrained weight is trained on 1000 classification dataset.

References

Karen Simonyan, Andrew Zisserman
Very Deep Convolutional Networks for Large-Scale Image Recognition

SERIALIZED = ('imsize', 'class_map', 'num_class')
WEIGHT_URL = 'https://renom.jp/docs/downloads/weights/Vgg16.h5'
build_data ( )

This function returns a function which creates input data and target data specified for VGG16.

Returns: Returns function which creates input data and target data.
Return type: (function)

Example

>>> builder = model.build_data()  # This will return function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
fit ( train_img_path_list=None , train_annotation_list=None , valid_img_path_list=None , valid_annotation_list=None , epoch=136 , batch_size=64 , augmentation=None , callback_end_epoch=None )

This function performs training with given data and hyper parameters.

Parameters:
  • train_img_path_list ( list ) – List of image path.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image path for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epoch.
  • batch_size ( int ) – Number of batch size.
  • augmentation ( Augmentation ) – Augmentation object.
  • callback_end_epoch ( function ) – Given function will be called at the end of each epoch.
Returns:

Training loss list and validation loss list.

Return type:

(tuple)

Example

>>> train_img_path_list, train_annot_list = ... # Define own data.
>>> valid_img_path_list, valid_annot_list = ...
>>> model = VGG16() # Any algorithm which provided by ReNomIMG here.
>>> model.fit(
...     # Feeds image and annotation data.
...     train_img_path_list,
...     train_annot_list,
...     valid_img_path_list,
...     valid_annot_list,
...     epoch=8,
...     batch_size=8)
>>>

Following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Number of current epoch.
  • model (Model) - Model object.
  • avg_train_loss_list (list) - List of average train loss of each epoch.
  • avg_valid_loss_list (list) - List of average valid loss of each epoch.
forward ( x )

Performs forward propagation. You can call this function using __call__ method.

Parameters: x ( ndarray , Node ) – Input to VGG16.
Returns: Returns raw output of VGG16.
Return type: (Node)

Example

>>> import numpy as np
>>> from renom_img.api.classification.vgg import VGG16
>>>
>>> x = np.random.rand(1, 3, 224, 224)
>>> class_map = ["dog", "cat"]
>>> model = VGG16(class_map)
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
get_optimizer ( current_epoch=None , total_epoch=None , current_batch=None , total_batch=None , **kwargs )

Returns an instance of Optimizer for training VGG16 algorithm. If all argument(current_epoch, total_epoch, current_batch, total_batch) are given, the learning rate is modified according to the number of training iterations or the constant learning rate is used.

Parameters:
  • current_epoch ( int ) – The number of current epoch.
  • total_epoch ( int ) – The number of total epoch.
  • current_batch ( int ) – The number of current batch.
  • total_batch ( int ) – The number of total batch.
Returns:

Optimizer object.

Return type:

(Optimizer)

loss ( x , y )

Loss function of VGG16 algorithm.

Parameters:
  • x ( ndarray , Node ) – Output of model.
  • y ( ndarray , Node ) – Target array.
Returns:

Loss between x and y.

Return type:

(Node)

Example

>>> builder = model.build_data()  # This will return function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list )

Perform prediction. Argument can be an image array, image path list or a image path.

Parameters: img_list ( ndarray , list , string ) – Image array, image path list or image path.
Returns: List of class of each image.
Return type: (list)
preprocess ( x )

Performs preprocess for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
Returns: Preprocessed data.
Return type: (ndarray)

Preprocessing for VGG is follows.

\[\begin{split}x_{red} -= 123.68 \\ x_{green} -= 116.779 \\ x_{blue} -= 103.939\end{split}\]
regularize ( )

Regularization term to a loss function.

Example

>>> x = numpu.random.rand(1, 3, 224, 224)
>>> y = numpy.random.rand(1, (5*2+20)*7*7)
>>> model = VGG16()
>>> loss = model.loss(x, y)
>>> reg_loss = loss + model.regularize() # Add weight decay term.
class VGG19 ( class_map=[] , imsize=(224 , 224) , load_pretrained_weight=False , train_whole_network=False )

VGG19 model.

If the argument load_weight is True, pretrained weight will be downloaded. The pretrained weight is trained using ILSVRC2012.

Parameters:
  • class_map ( array ) – Array of class names
  • imsize ( int or tuple ) – Input image size
  • train_whole_network ( bool ) – True if the overall model is trained, otherwise False
  • load_pretrained_weight ( bool , str ) – If true, pretrained weight will be downloaded to current directory. If string is given, pretrained weight will be saved as given name.

Note

if the argument num_class is not 1000, last dense layer will be reset because the pretrained weight is trained on 1000 classification dataset.

References

Karen Simonyan, Andrew Zisserman
Very Deep Convolutional Networks for Large-Scale Image Recognition

SERIALIZED = ('imsize', 'class_map', 'num_class')
WEIGHT_URL = 'https://renom.jp/docs/downloads/weights/Vgg19.h5'
build_data ( )

This function returns a function which creates input data and target data specified for VGG19.

Returns: Returns function which creates input data and target data.
Return type: (function)

Example

>>> builder = model.build_data()  # This will return function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
fit ( train_img_path_list=None , train_annotation_list=None , valid_img_path_list=None , valid_annotation_list=None , epoch=136 , batch_size=64 , augmentation=None , callback_end_epoch=None )

This function performs training with given data and hyper parameters.

Parameters:
  • train_img_path_list ( list ) – List of image path.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image path for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epoch.
  • batch_size ( int ) – Number of batch size.
  • augmentation ( Augmentation ) – Augmentation object.
  • callback_end_epoch ( function ) – Given function will be called at the end of each epoch.
Returns:

Training loss list and validation loss list.

Return type:

(tuple)

Example

>>> train_img_path_list, train_annot_list = ... # Define own data.
>>> valid_img_path_list, valid_annot_list = ...
>>> model = VGG19() # Any algorithm which provided by ReNomIMG here.
>>> model.fit(
...     # Feeds image and annotation data.
...     train_img_path_list,
...     train_annot_list,
...     valid_img_path_list,
...     valid_annot_list,
...     epoch=8,
...     batch_size=8)
>>>

Following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Number of current epoch.
  • model (Model) - Model object.
  • avg_train_loss_list (list) - List of average train loss of each epoch.
  • avg_valid_loss_list (list) - List of average valid loss of each epoch.
forward ( x )

Performs forward propagation. You can call this function using __call__ method.

Parameters: x ( ndarray , Node ) – Input to VGG19.
Returns: Returns raw output of VGG19.
Return type: (Node)

Example

>>> import numpy as np
>>> from renom_img.api.classification.vgg import VGG19
>>>
>>> x = np.random.rand(1, 3, 224, 224)
>>> class_map = ["dog", "cat"]
>>> model = VGG19(class_map)
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
get_optimizer ( current_epoch=None , total_epoch=None , current_batch=None , total_batch=None , **kwargs )

Returns an instance of Optimizer for training VGG19 algorithm. If all argument(current_epoch, total_epoch, current_batch, total_batch) are given, the learning rate is modified according to the number of training iterations or the constant learning rate is used.

Parameters:
  • current_epoch ( int ) – The number of current epoch.
  • total_epoch ( int ) – The number of total epoch.
  • current_batch ( int ) – The number of current batch.
  • total_batch ( int ) – The number of total batch.
Returns:

Optimizer object.

Return type:

(Optimizer)

loss ( x , y )

Loss function of VGG19 algorithm.

Parameters:
  • x ( ndarray , Node ) – Output of model.
  • y ( ndarray , Node ) – Target array.
Returns:

Loss between x and y.

Return type:

(Node)

Example

>>> builder = model.build_data()  # This will return function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list )

Perform prediction. Argument can be an image array, image path list or a image path.

Parameters: img_list ( ndarray , list , string ) – Image array, image path list or image path.
Returns: List of class of each image.
Return type: (list)
preprocess ( x )

Performs preprocess for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
Returns: Preprocessed data.
Return type: (ndarray)

Preprocessing for VGG is follows.

\[\begin{split}x_{red} -= 123.68 \\ x_{green} -= 116.779 \\ x_{blue} -= 103.939\end{split}\]
regularize ( )

Regularization term to a loss function.

Example

>>> x = numpu.random.rand(1, 3, 224, 224)
>>> y = numpy.random.rand(1, (5*2+20)*7*7)
>>> model = VGG19()
>>> loss = model.loss(x, y)
>>> reg_loss = loss + model.regularize() # Add weight decay term.