hyperpose.Model package

Submodules

hyperpose.Model.backbones module

class hyperpose.Model.backbones.MobilenetV1_backbone(scale_size=8, data_format='channels_last', pretraining=False)

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

cal_loss

conv_block

count_params

print_params

separable_conv_block

cal_loss(self, label, predict)
conv_block(self, n_filter=32, in_channels=3, filter_size=3, 3, strides=1, 1, padding='SAME', name='conv_block')
forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
separable_conv_block(self, n_filter=32, in_channels=3, filter_size=3, 3, strides=1, 1, name='spconv_block')
class hyperpose.Model.backbones.MobilenetV2_backbone(scale_size=8, data_format='channels_last', pretraining=False)

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

InvertedResidual([n_filter, in_channels, …])

Attributes

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

cal_loss

count_params

print_params

class InvertedResidual(n_filter=128, in_channels=128, strides=1, 1, exp_ratio=6, data_format='channels_first', name='block')

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

count_params

print_params

forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
cal_loss(self, label, predict)
forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
class hyperpose.Model.backbones.Resnet18_backbone(n_filter=512, in_channels=3, scale_size=8, data_format='channels_first', pretraining=False)

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

Res_block(n_filter, in_channels[, strides, …])

Attributes

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

count_params

print_params

class Res_block(n_filter, in_channels, strides=1, 1, is_down_sample=False, data_format='channels_first', name='res_block')

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

count_params

print_params

forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
class hyperpose.Model.backbones.Resnet50_backbone(in_channels=3, n_filter=64, scale_size=8, data_format='channels_first', pretraining=False, use_pool=True)

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

Basic_block([in_channels, n_filter, …])

Attributes

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

cal_loss

count_params

print_params

class Basic_block(in_channels=64, n_filter=64, strides=1, 1, data_format='channels_first', name='basic_block')

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

count_params

print_params

forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
cal_loss(self, label, predict)
forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
class hyperpose.Model.backbones.vgg16_backbone(in_channels=3, scale_size=8, data_format='channels_first', pretraining=False)

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

cal_loss

conv_block

count_params

print_params

cal_loss(self, label, predict)
conv_block(self, n_filter=32, in_channels=3, filter_size=3, 3, strides=1, 1, act=None, padding='SAME', name='block')
forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
class hyperpose.Model.backbones.vgg19_backbone(in_channels=3, scale_size=8, data_format='channels_first', pretraining=False)

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

cal_loss

conv_block

count_params

print_params

cal_loss(self, label, predict)
conv_block(self, n_filter=32, in_channels=3, filter_size=3, 3, strides=1, 1, act=None, padding='SAME', name='conv_default')
forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)
class hyperpose.Model.backbones.vggtiny_backbone(in_channels=3, scale_size=8, data_format='channels_first', pretraining=False)

Bases: tensorlayer.models.core.Model

Attributes
all_drop
all_layers

Return all layers of this network in a list.

all_params
all_weights

Return all weights of this network in a list.

config
inputs
n_weights

Return the number of weights (parameters) in this network.

nontrainable_weights

Return nontrainable weights of this network in a list.

outputs
trainable_weights

Return trainable weights of this network in a list.

Methods

__call__(self, inputs[, is_train])

Forward input tensors through this network by calling.

as_layer(self)

Return this network as a ModelLayer so that it can be integrated into another Model.

eval(self)

Set this network in evaluation mode.

forward(self, x)

Network forwarding given input tensors

get_layer(self[, name, index])

Network forwarding given input tensors

infer(self)

Set this network in evaluation mode.

load(filepath[, load_weights])

Load model from a given file, which should be previously saved by Model.save().

load_weights(self, filepath[, format, …])

Load model weights from a given file, which should be previously saved by self.save_weights().

print_all_layers(self)

release_memory(self)

WARNING: This function should be called with great caution.

save(self, filepath[, save_weights, …])

Save model into a given file.

save_weights(self, filepath[, format])

Input filepath, save model weights into a file of given format.

test(self)

Set this network in evaluation mode.

train(self)

Set this network in training mode.

cal_loss

conv_block

count_params

print_params

cal_loss(self, label, predict)
conv_block(self, n_filter=32, in_channels=3, filter_size=3, 3, strides=1, 1, act=tensorflow.nn.relu, padding='SAME', name='block')
forward(self, x)

Network forwarding given input tensors

Parameters
inputsTensor or list of Tensors

input tensor(s)

kwargs :

For other keyword-only arguments.

Returns
output tensor(s)Tensor or list of Tensor(s)

hyperpose.Model.common module

class hyperpose.Model.common.MPIIPart

Bases: enum.Enum

An enumeration.

Head = 13
LAnkle = 5
LElbow = 10
LHip = 3
LKnee = 4
LShoulder = 9
LWrist = 11
Neck = 12
RAnkle = 0
RElbow = 7
RHip = 2
RKnee = 1
RShoulder = 8
RWrist = 6
static from_coco(human)
class hyperpose.Model.common.Profiler

Bases: object

Methods

__call__(self, name, duration)

Call self as a function.

report

report(self)
hyperpose.Model.common.draw_humans(npimg, humans)
hyperpose.Model.common.get_op(graph, name)
hyperpose.Model.common.get_optim(optim_type)
hyperpose.Model.common.get_sample_images(w, h)
hyperpose.Model.common.init_log(config)
hyperpose.Model.common.load_graph(model_file)

Load a freezed graph from file.

hyperpose.Model.common.log(msg)
hyperpose.Model.common.measure(f, name=None)
hyperpose.Model.common.pad_image(img, stride, pad_value=0.0)
hyperpose.Model.common.plot_humans(image, heatMat, pafMat, humans, name)
hyperpose.Model.common.read_imgfile(path, width, height, data_format='channels_last')

Read image file and resize to network input size.

hyperpose.Model.common.regulize_loss(target_model, weight_decay_factor)
hyperpose.Model.common.rename_tensor(x, name)
hyperpose.Model.common.tf_repeat(tensor, repeats)

Args:

input: A Tensor. 1-D or higher. repeats: A list. Number of repeat for each dimension, length must be the same as the number of dimensions in input

Returns:

A Tensor. Has the same type as input. Has the shape of tensor.shape * repeats

hyperpose.Model.human module

class hyperpose.Model.human.BodyPart(parts, u_idx, part_idx, x, y, score, w=- 1, h=- 1)

Bases: object

part_idx : part index(eg. 0 for nose) x, y: coordinate of body part score : confidence score

Methods

get_part_name

get_x

get_y

get_part_name(self)
get_x(self)
get_y(self)
class hyperpose.Model.human.Human(parts, limbs, colors)

Bases: object

body_parts: list of BodyPart

Methods

draw_human

get_area

get_bbx

get_global_id

get_partnum

get_score

print

scale

draw_human(self, img)
get_area(self)
get_bbx(self)
get_global_id(self)
get_partnum(self)
get_score(self)
print(self)
scale(self, scale_w, scale_h)

Module contents

hyperpose.Model.get_evaluate(config)

get evaluate pipeline based on config object

construct evaluate pipeline based on the chosen model_type and dataset_type, the evaluation metric fellows the official metrics of the chosen dataset.

the returned evaluate pipeline can be easily used by evaluate(model,dataset), where model is obtained by Model.get_model(), dataset is obtained by Dataset.get_dataset()

the evaluate pipeline will: 1.loading newest model at path ./save_dir/model_name/model_dir/newest_model.npz 2.perform inference and parsing over the chosen evaluate dataset 3.visualize model output in evaluation in directory ./save_dir/model_name/eval_vis_dir 4.output model metrics by calling dataset.official_eval()

Parameters
arg1config object

the config object return by Config.get_config() function, which includes all the configuration information.

Returns
function

a evaluate pipeline function which takes model and dataset as input, and output model metrics

hyperpose.Model.get_model(config)

get model based on config object

construct and return a model based on the configured model_type and model_backbone. each preset model architecture has a default backbone, replace it with chosen common model_backbones allow user to change model computation complexity to adapt to application scene.

Parameters
arg1config object

the config object return by Config.get_config() function, which includes all the configuration information.

Returns
tensorlayer.models.MODEL

a model object inherited from tensorlayer.models.MODEL class, has configured model architecture and chosen model backbone. can be user defined architecture by using Config.set_model_architecture() function.

hyperpose.Model.get_postprocess(model_type)

get postprocess function based model_type

get the postprocess function of the specified kind of model to help user construct thier own evaluate pipeline rather than using the integrated train or evaluate pipeline directly when in need

the postprocess function is able to parse the model output feature map and output parsed human objects of Human class, which contains all dectected keypoints.

Parameters
arg1Config.MODEL

a enum value of enum class Config.MODEL

Returns
function

a postprocess function of the specified kind of model

hyperpose.Model.get_preprocess(model_type)

get preprocess function based model_type

get the preprocess function of the specified kind of model to help user construct thier own train and evaluate pipeline rather than using the integrated train or evaluate pipeline directly when in need.

the preprocess function is able to convert the image and annotation to the model output format for training or evaluation.

Parameters
arg1Config.MODEL

a enum value of enum class Config.MODEL

Returns
function

a preprocess function of the specified kind of model

hyperpose.Model.get_pretrain(config)
hyperpose.Model.get_train(config)

get train pipeline based on config object

construct train pipeline based on the chosen model_type and dataset_type, default is single train pipeline performed on single GPU, can be parallel train pipeline use function Config.set_train_type()

the returned train pipeline can be easily used by train(model,dataset), where model is obtained by Model.get_model(), dataset is obtained by Dataset.get_dataset()

the train pipeline will: 1.store and restore ckpt in directory ./save_dir/model_name/model_dir 2.log loss information in directory ./save_dir/model_name/log.txt 3.visualize model output periodly during training in directory ./save_dir/model_name/train_vis_dir the newest model is at path ./save_dir/model_name/model_dir/newest_model.npz

Parameters
arg1config object

the config object return by Config.get_config() function, which includes all the configuration information.

Returns
function

a train pipeline function which takes model and dataset as input, can be either single train or parallel train pipeline.

hyperpose.Model.get_visualize(model_type)

get visualize function based model_type

get the visualize function of the specified kind of model to help user construct thier own evaluate pipeline rather than using the integrated train or evaluate pipeline directly when in need

the visualize function is able to visualize model’s output feature map, which is helpful for training and evaluation analysis.

Parameters
arg1Config.MODEL

a enum value of enum class Config.MODEL

Returns
function

a visualize function of the specified kind of model