Skip to content

numpy Tensor Operation Commands

Commands for handling numpy files formatted as tensors for snr inputs.

Tensor Specification

A numpy tensor can be specified via Tensor Specification.

The Tensor Specification format is that of comma-separated key and value pairs, as in 'key1=val1,key2=val2,...'.

Available keys

Key Description
shape Tensor shape. Dimension shapes are concatenated by x. Example: 1x224x224x3
dtype Tensor data type, defaults to float32
val Tensor initial values. Can be set to a pre-defined scalar or to random values inside a range. A range is defined by two numbers separated by ... Example: 0.0..1.0

Example Define a tensor with 1x128x128x16 shape, of float32 type and containing random numbers from -1.0 to 1.0.

shape=1x128x128x16,val=-1.0..1.0

The following help is also available.

$ softneuro help tensor_spec
usage: shape=SHAPE[,dtype=DTYPE][,val=VAL]

The tensor specification.

[REQUIRED]
    SHAPE  a shape of tensor. It is given as numbers concatenated by 'x' (e.g.
           1x224x224x3).

[OPTIONS]
    DTYPE  a data type. The default is 'float32'.
    VAL    element values. It is given as a number for constant values (e.g.
           0.5) or two numbers concatenated by '..' for random values between a
           range (e.g. 0.0..1.0). The default is '-1..1'.

[EXAMPLE]
    shape=1x128x128x16,val=-0.5..2
        represetns a tensor whose shape is 1x128x128x16, data type is 'float32'
        and elements have random value from -0.5 to 2.

mknpy

Create a tensor and save it in numpy format.

Usage
usage: softneuro mknpy [--help] SPEC ONPY

Arguments

Argument Description
SPEC Tensor Specification.
ONPY Output numpy file name.

Flags

Flag Description
-h, --help Shows the command help.

Example
Creates a tensor.npy file containing the tensor data at the execution directory.
※There's no terminal output

$ softneuro mknpy "shape=1x128x128x16,val=-1.0..1.0" tensor.npy

attrnpy

Shows tensor attributes, as listed below.

  • NAME : File name
  • DTYPE : Data type
  • SHAPE : Shape
  • RANGE : Data range
  • AVERAGE : Data average
  • STDEV : Data standard deviation

Usage
usage: softneuro attrnpy [--help] NPY...

Arguments

Argument Description
NPY numpy file to have its attributes shown.

Flags

Flag Description
-h, --help Shows the command help.

Example

$ softneuro attrnpy tensor.npy
NAME          DTYPE    SHAPE       RANGE                  AVERAGE     STDEV
tensor.npy  float32  1x128x128x16  -0.999991:0.999995  0.00036936  0.576519

viewnpy

Shows the values from a numpy file.

Usage
usage: softneuro viewnpy [--from INDICES] [--cols COLS] [--help] NPY

Arguments

Argument Description
NPY numpy file to have its values shown.

Flags

Flag Description
--from INDICES Indices from where to start showing data.
--cols COL Specify columns to be displayed.
-h, --help Shows the command help.

Example

$ softneuro viewnpy --from "127,127,10" tensor.npy
(127,127,10)        -0.459925,      -0.40616,
(127,127,12)          0.89318,     -0.275693,     -0.337535,      0.115791]

cmpnpy

Compares two numpy files values, showing their signal-to-noise ratio in db. As a rule of thumb, 100db or more indicates a match, 60db or more indicates reasonable similarity, 20db or more indicates some similarity, less than 20db indicates not a match.

Usage
usage: softneuro cmpnpy [--axis A] [--help] TRUENPY TGTNPY

Arguments

Argument Description
TRUENPY A numpy file or a directory containing numpy files which have the correct numbers.
TGTNPY A numpy file or a directory containing numpy files which have the data to be compared.

Flags

Flag Description
--axis A Which axis to be compared.
-h, --help Shows the command help.

Example

$ softneuro cmpnpy tensor.npy tensor2.npy
SNR(db)  PSNR(db)     MIN:MAX
> 200    > 200         -1:1