renom_img.api.classification

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

VGG11 model.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. Pretrained weights have not been prepared for VGG-11 yet, so this must either be set to False, or to a user-defined string that specifies a local pretrained weights filename.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If true, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.vgg import VGG11
>>>
>>> class_map = ["dog", "cat"]
>>> model = VGG11(class_map, imsize=(224,224), load_pretrained_weight=False, train_whole_network=True)

Note

VGG11 does not currently have pretrained weights available, so you must use randomly initialized weights or provide user-trained weights. If you would like to initialize your model with ImageNet pretrained weights, please use VGG16, VGG19 or any ResNet/ResNeXt model in ReNom.

References

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = VGG11(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> 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.
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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = VGG11(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class VGG16 ( class_map=None , imsize=(224 , 224) , load_pretrained_weight=False , train_whole_network=False )

VGG16 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int or tuple ) – Input image size.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.vgg import VGG16
>>>
>>> class_map = ["dog", "cat"]
>>> model = VGG16(class_map, imsize=(224,224), load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = VGG16(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> 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.
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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = VGG16(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class VGG19 ( class_map=None , imsize=(224 , 224) , load_pretrained_weight=False , train_whole_network=False )

VGG19 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.vgg import VGG19
>>>
>>> class_map = ["dog", "cat"]
>>> model = VGG19(class_map, imsize=(224,224), load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = VGG19(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> 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.
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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = VGG19(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class ResNet101 ( class_map=None , imsize=(224 , 224) , plateau=False , load_pretrained_weight=False , train_whole_network=False )

ResNet101 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • plateau ( bool ) – Specifies whether or not error plateau learning rate adjustment should be used. If True, learning rate is automatically decreased when training loss reaches a plateau.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.resnet import ResNet101
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet101(class_map, imsize=(224,224), plateau=True, load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition

build_data ( )

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = ResNet101(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> x = np.random.rand(1, 3, 224, 224)
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet101(class_map)
>>>
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
loss ( x , y )

Loss function of ResNet101 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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = ResNet101(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class ResNet152 ( class_map=None , imsize=(224 , 224) , plateau=False , load_pretrained_weight=False , train_whole_network=False )

ResNet152 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • plateau ( bool ) – Specifies whether or not error plateau learning rate adjustment should be used. If True, learning rate is automatically decreased when training loss reaches a plateau.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.resnet import ResNet152
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet152(class_map, imsize=(224,224), plateau=True, load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition

build_data ( )

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = ResNet152(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> x = np.random.rand(1, 3, 224, 224)
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet152(class_map)
>>>
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
loss ( x , y )

Loss function of ResNet152 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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = ResNet152(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class ResNet18 ( class_map=None , imsize=(224 , 224) , plateau=False , load_pretrained_weight=False , train_whole_network=False )

ResNet18 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • plateau ( bool ) – Specifies whether or not error plateau learning rate adjustment should be used. If True, learning rate is automatically decreased when training loss reaches a plateau.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.resnet import ResNet18
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet18(class_map, imsize=(224,224), plateau=True, load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition

build_data ( )

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = ResNet18(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> x = np.random.rand(1, 3, 224, 224)
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet18(class_map)
>>>
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
loss ( x , y )

Loss function of ResNet18 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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = ResNet18(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class ResNet34 ( class_map=None , imsize=(224 , 224) , plateau=False , load_pretrained_weight=False , train_whole_network=False )

ResNet34 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • plateau ( bool ) – Specifies whether or not error plateau learning rate adjustment should be used. If True, learning rate is automatically decreased when training loss reaches a plateau.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.resnet import ResNet34
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet34(class_map, imsize=(224,224), plateau=True, load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition

build_data ( )

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = ResNet34(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> x = np.random.rand(1, 3, 224, 224)
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet34(class_map)
>>>
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
loss ( x , y )

Loss function of ResNet34 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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = ResNet34(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class ResNet50 ( class_map=None , imsize=(224 , 224) , plateau=False , load_pretrained_weight=False , train_whole_network=False )

ResNet50 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • plateau ( bool ) – Specifies whether or not error plateau learning rate adjustment should be used. If True, learning rate is automatically decreased when training loss reaches a plateau.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.resnet import ResNet50
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet50(class_map, imsize=(224,224), plateau=True, load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition

build_data ( )

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = ResNet50(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> x = np.random.rand(1, 3, 224, 224)
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNet50(class_map)
>>>
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
loss ( x , y )

Loss function of ResNet50 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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = ResNet50(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class ResNeXt101 ( class_map=[] , imsize=(224 , 224) , cardinality=32 , plateau=False , load_pretrained_weight=False , train_whole_network=False )

ResNeXt101 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • cardinality ( int ) – Number of groups in group convolution layers (default = 32)
  • plateau ( bool ) – Specifies whether or not error plateau learning rate adjustment should be used. If True, learning rate is automatically decreased when training loss reaches a plateau.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.resnext import ResNeXt101
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNeXt101(class_map, imsize=(224,224), plateau=True, load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

Saining Xie, Ross Girshick, Piotr Dollar, Zhuowen Tu, Kaiming He
Aggregated Residual Transformations for Deep Neural Networks

build_data ( )

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = ResNeXt101(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> x = np.random.rand(1, 3, 224, 224)
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNeXt101(class_map)
>>>
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
loss ( x , y )

Loss function of ResNeXt101 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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = ResNeXt101(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.
class ResNeXt50 ( class_map=[] , imsize=(224 , 224) , cardinality=32 , plateau=False , load_pretrained_weight=False , train_whole_network=False )

ResNeXt50 model.

If the argument load_pretrained_weight is True, pretrained weights will be downloaded. The pretrained weights were trained using ILSVRC2012.

Parameters:
  • class_map ( list , dict ) – List of class names.
  • imsize ( int , tuple ) – Input image size.
  • cardinality ( int ) – Number of groups in group convolution layers (default = 32)
  • plateau ( bool ) – Specifies whether or not error plateau learning rate adjustment should be used. If True, learning rate is automatically decreased when training loss reaches a plateau.
  • load_pretrained_weight ( bool , str ) – Argument specifying whether or not to load pretrained weight values. If True, pretrained weights will be downloaded to the current directory and loaded as the initial weight values. If a string is given, weight values will be loaded and initialized from the weights in the given file name.
  • train_whole_network ( bool ) – Flag specifying whether to freeze or train the base layers of the model during training. If True, trains all layers of the model. If False, the convolutional base is frozen during training.

Example

>>> from renom_img.api.classification.resnext import ResNeXt50
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNeXt50(class_map, imsize=(224,224), plateau=True, load_pretrained_weight=True, train_whole_network=True)

Note

If the argument num_class is not equal to 1000, the last dense layer will be reset because the pretrained weight was trained on a 1000-class dataset.

References

Saining Xie, Ross Girshick, Piotr Dollar, Zhuowen Tu, Kaiming He
Aggregated Residual Transformations for Deep Neural Networks

build_data ( )

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

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 , optimizer=None , augmentation=None , callback_end_epoch=None )

This function performs training with the given data and hyperparameters.

Parameters:
  • train_img_path_list ( list ) – List of image paths.
  • train_annotation_list ( list ) – List of annotations.
  • valid_img_path_list ( list ) – List of image paths for validation.
  • valid_annotation_list ( list ) – List of annotations for validation.
  • epoch ( int ) – Number of training epochs.
  • batch_size ( int ) – 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 train data
>>> valid_img_path_list, valid_annot_list = ... # Define validation data
>>> class_map = ... # Define class map
>>> model = ResNeXt50(class_map) # Specify any algorithm provided by ReNomIMG API 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)
>>>

The following arguments will be given to the function callback_end_epoch .

  • epoch (int) - Current epoch number.
  • 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 the __call__ method.

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

Example

>>> import numpy as np
>>> x = np.random.rand(1, 3, 224, 224)
>>>
>>> class_map = ["dog", "cat"]
>>> model = ResNeXt50(class_map)
>>>
>>> y = model.forward(x) # Forward propagation.
>>> y = model(x)  # Same as above result.
loss ( x , y )

Loss function of ResNeXt50 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 a builder function.
>>> x, y = builder(image_path_list, annotation_list)
>>> z = model(x)
>>> loss = model.loss(z, y)
predict ( img_list , batch_size=1 , return_scores=False )

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.
  • batch_size ( int ) – Batch size for processing input images.
  • return_scores ( bool ) – Optional flag to return prediction scores for all classes when set to True. Default is False.
Returns:

List of predicted class for each image. Also returns array of all probability scores if return_scores is set to True.

Return type:

(array)

preprocess ( x )

Performs preprocessing for a given array.

Parameters: x ( ndarray , Node ) – Image array for preprocessing.
regularize ( )

Adds a regularization term to the loss function.

Example

>>> x = numpy.random.rand(1, 3, 224, 224)  # Input image
>>> y = ...  # Ground-truth label
>>>
>>> class_map = ['cat', 'dog']
>>> model = ResNeXt50(class_map)
>>>
>>> z = model(x)  # Forward propagation
>>> loss = model.loss(z, y)  # Loss calculation
>>> reg_loss = loss + model.regularize()  # Add weight decay term.