tensorcv.callbacks.base.
Callback
[source]¶Bases: object
base class for callbacks
epochs_completed
¶global_step
¶tensorcv.callbacks.debug.
CheckScalar
(tensors, periodic=1)[source]¶Bases: tensorcv.callbacks.base.Callback
print scalar tensor values during training .. attribute:: _tensors
_names
¶tensorcv.callbacks.group.
Callbacks
(cbs)[source]¶Bases: tensorcv.callbacks.base.Callback
group all the callback
tensorcv.callbacks.hooks.
Callback2Hook
(cb)[source]¶Bases: tensorflow.python.training.session_run_hook.SessionRunHook
after_run
(rct, val)[source]¶Called after each call to run().
The run_values argument contains results of requested ops/tensors by before_run().
The run_context argument is the same one send to before_run call. run_context.request_stop() can be called to stop the iteration.
If session.run() raises any exceptions then after_run() is not called.
Parameters: |
|
---|
before_run
(rct)[source]¶Called before each call to run().
You can return from this call a SessionRunArgs object indicating ops or tensors to add to the upcoming run() call. These ops/tensors will be run together with the ops/tensors originally passed to the original run() call. The run args you return can also contain feeds to be added to the run() call.
The run_context argument is a SessionRunContext that provides information about the upcoming run() call: the originally requested op/tensors, the TensorFlow Session.
At this point graph is finalized and you can not add ops.
Parameters: | run_context – A SessionRunContext object. |
---|---|
Returns: | None or a SessionRunArgs object. |
tensorcv.callbacks.hooks.
Infer2Hook
(inferencer)[source]¶Bases: tensorflow.python.training.session_run_hook.SessionRunHook
after_run
(rct, val)[source]¶Called after each call to run().
The run_values argument contains results of requested ops/tensors by before_run().
The run_context argument is the same one send to before_run call. run_context.request_stop() can be called to stop the iteration.
If session.run() raises any exceptions then after_run() is not called.
Parameters: |
|
---|
before_run
(rct)[source]¶Called before each call to run().
You can return from this call a SessionRunArgs object indicating ops or tensors to add to the upcoming run() call. These ops/tensors will be run together with the ops/tensors originally passed to the original run() call. The run args you return can also contain feeds to be added to the run() call.
The run_context argument is a SessionRunContext that provides information about the upcoming run() call: the originally requested op/tensors, the TensorFlow Session.
At this point graph is finalized and you can not add ops.
Parameters: | run_context – A SessionRunContext object. |
---|---|
Returns: | None or a SessionRunArgs object. |
tensorcv.callbacks.hooks.
Prediction2Hook
(prediction)[source]¶Bases: tensorflow.python.training.session_run_hook.SessionRunHook
after_run
(rct, val)[source]¶Called after each call to run().
The run_values argument contains results of requested ops/tensors by before_run().
The run_context argument is the same one send to before_run call. run_context.request_stop() can be called to stop the iteration.
If session.run() raises any exceptions then after_run() is not called.
Parameters: |
|
---|
before_run
(rct)[source]¶Called before each call to run().
You can return from this call a SessionRunArgs object indicating ops or tensors to add to the upcoming run() call. These ops/tensors will be run together with the ops/tensors originally passed to the original run() call. The run args you return can also contain feeds to be added to the run() call.
The run_context argument is a SessionRunContext that provides information about the upcoming run() call: the originally requested op/tensors, the TensorFlow Session.
At this point graph is finalized and you can not add ops.
Parameters: | run_context – A SessionRunContext object. |
---|---|
Returns: | None or a SessionRunArgs object. |
tensorcv.callbacks.inference.
FeedInference
(inputs, periodic=1, inferencers=[], extra_cbs=None, infer_batch_size=None)[source]¶Bases: tensorcv.callbacks.inference.InferenceBase
tensorcv.callbacks.inference.
GANInference
(inputs=None, periodic=1, inferencers=None, extra_cbs=None)[source]¶Bases: tensorcv.callbacks.inference.InferenceBase
tensorcv.callbacks.inference.
FeedInferenceBatch
(inputs, periodic=1, batch_count=10, inferencers=[], extra_cbs=None, infer_batch_size=None)[source]¶Bases: tensorcv.callbacks.inference.FeedInference
do not use all validation data
tensorcv.callbacks.inferencer.
InferImages
(im_name, prefix=None, color=False, tanh=False)[source]¶tensorcv.callbacks.inferencer.
InferOverlay
(im_name, prefix=None, color=False, tanh=False)[source]¶tensorcv.callbacks.inputs.
FeedInput
(dataflow, placeholders)[source]¶Bases: tensorcv.callbacks.base.Callback
input using feed
tensorcv.callbacks.monitors.
Monitors
(mons)[source]¶Bases: tensorcv.callbacks.monitors.TrainingMonitor
group monitors
tensorcv.callbacks.trigger.
PeriodicTrigger
(trigger_cb, every_k_steps=None, every_k_epochs=None)[source]¶Bases: tensorcv.callbacks.base.ProxyCallback
may not need
tensorcv.dataflow.dataset.BSDS500.
BSDS500
(name, data_dir='', shuffle=True, normalize=None, is_mask=False, normalize_fnc=<function identity>, resize=None)[source]¶tensorcv.dataflow.dataset.MNIST.
MNIST
(name, data_dir='', shuffle=True, normalize=None)[source]¶tensorcv.dataflow.base.
DataFlow
[source]¶Bases: object
base class for dataflow
epochs_completed
¶tensorcv.dataflow.common.
dense_to_one_hot
(labels_dense, num_classes)[source]¶Convert class labels from scalars to one-hot vectors.
tensorcv.dataflow.image.
ImageData
(ext_name, data_dir='', shuffle=True, normalize=None)[source]¶tensorcv.dataflow.image.
DataFromFile
(ext_name, data_dir='', num_channel=None, shuffle=True, normalize=None, batch_dict_name=None, normalize_fnc=<function identity>)[source]¶Bases: tensorcv.dataflow.base.RNGDataFlow
Base class for image from files
tensorcv.dataflow.image.
ImageLabelFromFolder
(ext_name, data_dir='', num_channel=None, label_dict=None, num_class=None, one_hot=False, shuffle=True, normalize=None, resize=None, resize_crop=None, batch_dict_name=None, pf=<function identity>)[source]¶Bases: tensorcv.dataflow.image.ImageFromFile
read image data with label in subfolder name
tensorcv.dataflow.image.
ImageLabelFromFile
(ext_name, data_dir='', label_file_name='', num_channel=None, one_hot=False, label_dict={}, num_class=None, shuffle=True, normalize=None, resize=None, resize_crop=None, batch_dict_name=None, pf=<function identity>)[source]¶Bases: tensorcv.dataflow.image.ImageLabelFromFolder
read image data with label in a separate file txt
tensorcv.dataflow.image.
ImageFromFile
(ext_name, data_dir='', num_channel=None, shuffle=True, normalize=None, normalize_fnc=<function identity>, resize=None, resize_crop=None, batch_dict_name=None, pf=<function identity>)[source]¶tensorcv.models.base.
ModelDes
[source]¶Bases: object
base model for ModelDes
get_global_step
¶model_input
¶tensorcv.models.base.
BaseModel
[source]¶Bases: tensorcv.models.base.ModelDes
Model with single loss and single optimizer
default_collection
¶tensorcv.models.base.
GANBaseModel
(input_vec_length, learning_rate)[source]¶Bases: tensorcv.models.base.ModelDes
Base model for GANs
d_collection
¶g_collection
¶tensorcv.models.layers.
batch_norm
(x, train=True, name='bn')[source]¶batch normal
Parameters: | |
---|---|
Returns: | tf.tensor with name ‘name’ |
tensorcv.models.layers.
conv
(x, filter_size, out_dim, name='conv', stride=1, padding='SAME', nl=<function identity>, data_dict=None, init_w=None, init_b=None, use_bias=True, wd=None, trainable=True)[source]¶2D convolution
Parameters: |
|
---|---|
Returns: | tf.tensor with name ‘output’ |
tensorcv.models.layers.
dconv
(x, filter_size, out_dim=None, out_shape=None, out_shape_by_tensor=None, name='dconv', stride=2, padding='SAME', nl=<function identity>, data_dict=None, init_w=None, init_b=None, wd=None, trainable=True)[source]¶2D deconvolution
Parameters: |
|
---|---|
Returns: | tf.tensor with name ‘output’ |
tensorcv.models.layers.
dropout
(x, keep_prob, is_training, name='dropout')[source]¶Dropout
Parameters: | |
---|---|
Returns: | tf.tensor with name ‘name’ |
tensorcv.models.layers.
fc
(x, out_dim, name='fc', nl=<function identity>, init_w=None, init_b=None, data_dict=None, wd=None, trainable=True, re_dict=False)[source]¶Fully connected layer
Parameters: | |
---|---|
Returns: | tf.tensor with name ‘output’ |
tensorcv.models.layers.
get_shape2D
(in_val)[source]¶Return a 2D shape
Parameters: | in_val (int or list with length 2) – |
---|---|
Returns: | list with length 2 |
tensorcv.models.layers.
get_shape4D
(in_val)[source]¶Return a 4D shape
Parameters: | in_val (int or list with length 2) – |
---|---|
Returns: | list with length 4 |
tensorcv.models.layers.
leaky_relu
(x, leak=0.2, name='LeakyRelu')[source]¶Allow a small non-zero gradient when the unit is not active
Parameters: |
|
---|---|
Returns: | tf.tensor with name ‘name’ |
tensorcv.models.layers.
max_pool
(x, name='max_pool', filter_size=2, stride=None, padding='VALID')[source]¶Max pooling layer
Parameters: | |
---|---|
Returns: | tf.tensor with name ‘name’ |
tensorcv.predicts.base.
Predictor
(config)[source]¶Bases: object
Base class for a predictor. Used to run all predictions.
config
¶PridectConfig – the config used for this predictor
model
¶ModelDes
input
¶DataFlow
sess
¶tf.Session
hooked_sess
¶tf.train.MonitoredSession
__init__
(config)[source]¶Inits Predictor with config (PridectConfig).
Will create session as well as monitored sessions for each predictions, and load pre-trained parameters.
Parameters: | config (PridectConfig) – the config used for this predictor |
---|
tensorcv.predicts.config.
PridectConfig
(dataflow=None, model=None, model_dir=None, model_name='', restore_vars=None, session_creator=None, predictions=None, batch_size=1, default_dirs=None)[source]¶Bases: object
__init__
(dataflow=None, model=None, model_dir=None, model_name='', restore_vars=None, session_creator=None, predictions=None, batch_size=1, default_dirs=None)[source]¶Args:
callbacks
¶tensorcv.predicts.predictions.
PredictionImage
(prediction_image_tensors, save_prefix, merge_im=False, tanh=False, color=False)[source]¶Bases: tensorcv.predicts.predictions.PredictionBase
Predict image output and save as files.
Images are saved every batch. Each batch result can be save in one image or individule images.
tensorcv.predicts.predictions.
PredictionScalar
(prediction_scalar_tensors, print_prefix)[source]¶Bases: tensorcv.predicts.predictions.PredictionBase
tensorcv.predicts.predictions.
PredictionMat
(prediction_tensors, save_prefix)[source]¶Bases: tensorcv.predicts.predictions.PredictionBase
tensorcv.predicts.predictions.
PredictionMeanScalar
(prediction_scalar_tensors, print_prefix)[source]¶tensorcv.predicts.simple.
SimpleFeedPredictor
(config)[source]¶Bases: tensorcv.predicts.base.Predictor
predictor with feed input
tensorcv.train.config.
TrainConfig
(dataflow=None, model=None, callbacks=[], session_creator=None, monitors=None, batch_size=1, max_epoch=100, summary_periodic=None, is_load=False, model_name=None, default_dirs=None)[source]¶Bases: object
callbacks
¶tensorcv.train.config.
GANTrainConfig
(dataflow=None, model=None, discriminator_callbacks=[], generator_callbacks=[], session_creator=None, monitors=None, batch_size=1, max_epoch=100, summary_d_periodic=None, summary_g_periodic=None, default_dirs=None)[source]¶Bases: tensorcv.train.config.TrainConfig
dis_callbacks
¶gen_callbacks
¶tensorcv.train.simple.
SimpleFeedTrainer
(config)[source]¶Bases: tensorcv.train.base.Trainer
single optimizer
tensorcv.utils.common.
apply_mask
(input_matrix, mask)[source]¶Get partition of input_matrix using index 1 in mask.
Parameters: |
|
---|---|
Returns: | A Tensor with elements from data with entries in mask equal to 1. |
tensorcv.utils.common.
apply_mask_inverse
(input_matrix, mask)[source]¶Get partition of input_matrix using index 0 in mask.
Parameters: |
|
---|---|
Returns: | A Tensor with elements from data with entries in mask equal to 0. |
tensorcv.utils.common.
get_tensors_by_names
(names)[source]¶Get a list of tensors by the input name list.
Parameters: | names (str) – A str or a list of str |
---|---|
Returns: | A list of tensors with name in input names. |
Warning
If more than one tensor have the same name in the graph. This function will only return the tensor with name NAME:0.
tensorcv.utils.common.
deconv_size
(input_height, input_width, stride=2)[source]¶Compute the feature size (height and width) after filtering with a specific stride. Mostly used for setting the shape for deconvolution.
Parameters: | |
---|---|
Returns: | (int, int) – Height and width of feature after filtering. |
tensorcv.utils.common.
match_tensor_save_name
(tensor_names, save_names)[source]¶Match tensor_names and corresponding save_names for saving the results of the tenors. If the number of tensors is less or equal to the length of save names, tensors will be saved using the corresponding names in save_names. Otherwise, tensors will be saved using their own names. Used for prediction or inference.
Parameters: | |
---|---|
Returns: | (list, list) – List of tensor names and list of names to save the tensors. |
tensorcv.utils.sesscreate.
NewSessionCreator
(target='', graph=None, config=None)[source]¶Bases: tensorflow.python.training.monitored_session.SessionCreator
tf.train.SessionCreator for a new session
tensorcv.utils.sesscreate.
ReuseSessionCreator
(sess)[source]¶Bases: tensorflow.python.training.monitored_session.SessionCreator
tf.train.SessionCreator for reuse an existed session
tensorcv.utils.utils.
get_rng
(obj=None)[source]¶This function is copied from tensorpack. Get a good RNG seeded with time, pid and the object. :param obj: some object to use to generate random seed.
Returns: | np.random.RandomState – the RNG. |
---|
tensorcv.utils.viz.
image_overlay
(im_1, im_2, color=True, normalize=True)[source]¶Overlay two images with the same size.
Parameters: | |
---|---|
Returns: | np.ndarray – an overlay image of im_1*0.5 + im_2*0.5 |
tensorcv.utils.viz.
intensity_to_rgb
(intensity, cmap='jet', normalize=False)[source]¶This function is copied from tensorpack. Convert a 1-channel matrix of intensities to an RGB image employing a colormap. This function requires matplotlib. See matplotlib colormaps for a list of available colormap.
Parameters: | |
---|---|
Returns: | np.ndarray – an RGB float32 image in range [0, 255], a colored heatmap. |
tensorcv.utils.viz.
save_merge_images
(images, merge_grid, save_path, color=False, tanh=False)[source]¶Save multiple images with same size into one larger image.
The best size number is int(max(sqrt(image.shape[0]),sqrt(image.shape[1]))) + 1
Parameters: |
|
---|
Example
The batch_size is 64, then the size is recommended [8, 8]. The batch_size is 32, then the size is recommended [6, 6].