neuralgym.ops¶
layers¶
layers
-
neuralgym.ops.layers.
HWNC_to_NHWC
(x, name='HWNC_to_NHWC')¶ Convert data format from HWNC to NHWC, may be used for re-indexing.
-
neuralgym.ops.layers.
NCHW_to_NHWC
(x, name='NCHW_to_NHWC')¶ Convert data format from NCHW to NHWC.
-
neuralgym.ops.layers.
NHWC_to_HWNC
(x, name='NHWC_to_HWNC')¶ Convert data format from NHWC to HWNC, may be used for re-indexing.
-
neuralgym.ops.layers.
NHWC_to_NCHW
(x, name='NHWC_to_NCHW')¶ Convert data format from NHWC to NCHW.
-
neuralgym.ops.layers.
apply_activation
(x, relu, activation_fn, name='activation')¶ Wrapper for apply activation.
Note activation_fn has higher execution level.
-
neuralgym.ops.layers.
avg_pool
(x, ksize=2, stride=2, padding='SAME', name='avg_pool')¶ Average pooling wrapper.
-
neuralgym.ops.layers.
batch_transformer
(U, thetas, out_size, name='BatchSpatialTransformer')¶ Batch Spatial Transformer Layer
Parameters: - Returns: float
- Tensor of size [num_batch*num_transforms,out_height,out_width,num_channels]
-
neuralgym.ops.layers.
bilinear_upsample
(x, scale=2)¶ Bilinear upsample.
Caffe bilinear upsample forked from https://github.com/ppwwyyxx/tensorpack Deterministic bilinearly-upsample the input images.
Parameters: - x (tf.Tensor) – a NHWC tensor
- scale (int) – the upsample factor
Returns: a NHWC tensor.
Return type: tf.Tensor
-
neuralgym.ops.layers.
concatenated_relu
(x, name='concatenated_relu')¶ Concatenated relu wrapper.
-
neuralgym.ops.layers.
flatten
(x, name='flatten')¶ Flatten wrapper.
-
neuralgym.ops.layers.
get_variable
(name, shape, initializer, weight_decay=0.0, dtype='float', trainable=True, freeze_weights=False)¶ Simple wrapper for get_variable.
-
neuralgym.ops.layers.
max_pool
(x, ksize=2, stride=2, padding='SAME', name='max_pool')¶ Max pooling wrapper.
-
neuralgym.ops.layers.
moving_average_var
(x, decay=0.99, initial_value=0.0, name='moving_average_var')¶ Moving_average_var.
-
neuralgym.ops.layers.
pixel_flow
(x, offset, interpolation='bilinear', name='pixel_flow')¶ pixel_flow: an operation to reorder pixels according to offsets.
Parameters: - x (tf.Tensor) – NHWC
- offset (tf.Tensor) – NHW2, 2 indicates (h, w) coordinates offset
- interpolation – bilinear, softmax
- name – name of module
References
[1] Spatial Transformer Networks: https://arxiv.org/abs/1506.02025 [2] https://github.com/ppwwyyxx/tensorpack
-
neuralgym.ops.layers.
scaled_elu
(x, name='scaled_elu')¶ Scaled elu wrapper.
-
neuralgym.ops.layers.
transformer
(U, theta, out_size=None, name='SpatialTransformer')¶ Spatial Transformer Layer.
Forked from tensorflow/models transformer.
summary_ops¶
summary ops.
-
neuralgym.ops.summary_ops.
scalar_summary
(name, value, sess=None, summary_writer=None, step=None)¶ Add scalar summary.
In addition to summary tf.Tensor and tf.Variable, this function supports summary of constant values by creating placeholder.
Example usage:
>>> scalar_summary('lr', lr)
Parameters: - name – name of summary variable
- value – numpy or tensorflow tensor
- summary_writer – if summary writer is provided, write to summary instantly
- step – if summary writer is provided, write to summary with step
Returns: None
-
neuralgym.ops.summary_ops.
filters_summary
(kernel, rescale=True, name='kernel')¶ Visualize filters and write to image summary.
Parameters: - kernel – kernel tensor
- rescale – rescale weights to [0, 1]
Returns: None
-
neuralgym.ops.summary_ops.
images_summary
(images, name, max_outs, color_format='BGR')¶ Summary images.
Note that images should be scaled to [-1, 1] for ‘RGB’ or ‘BGR’, [0, 1] for ‘GREY’.
Parameters: - images – images tensor (in NHWC format)
- name – name of images summary
- max_outs – max_outputs for images summary
- color_format – ‘BGR’, ‘RGB’ or ‘GREY’
Returns: None
-
neuralgym.ops.summary_ops.
gradients_summary
(y, x, norm=<function abs>, name='gradients_y_wrt_x')¶ Summary gradients w.r.t. x.
Sum of norm of \(\nabla_xy\).
Parameters: - y – y
- x – w.r.t x
- norm – norm function, default is tf.abs
- name – name of gradients summary
Returns: None
loss_ops¶
loss related functions
-
neuralgym.ops.loss_ops.
huber_loss
(x, delta=1.0, name='huber_loss')¶ Huber loss: https://en.wikipedia.org/wiki/Huber_loss.
Deprecated. Please use tensorflow huber loss implementation.
-
neuralgym.ops.loss_ops.
l1_loss
(x, y, name='l1_loss')¶ L1 loss: mean(abs(x-y)).
-
neuralgym.ops.loss_ops.
l2_loss
(x, y, name='l2_loss')¶ L2_loss: mean((x-y) ** 2).
-
neuralgym.ops.loss_ops.
tv_loss
(x, name='tv_loss')¶ tv_loss.
Deprecated. Please use tensorflow total_variation loss implementation.
image_ops¶
image related ops.
-
neuralgym.ops.image_ops.
np_random_crop
(image, shape, align=True)¶ Random crop.
shape from image.
Parameters: - image – numpy image, 2d or 3d
- shape – (height, width)
Returns: numpy image
-
neuralgym.ops.image_ops.
np_scale_to_shape
(image, shape, align=True)¶ Scale the image.
The minimum side of height or width will be scaled to or larger than shape.
Parameters: - image – numpy image, 2d or 3d
- shape – (height, width)
Returns: numpy image