Skip to content

Dnn Object & Basic commands

Dnn

Dnn (deep neural network) class consists of DnnNet.

softneuro.Dnn(filename, password, is_lazy)

Arguments

  • filename: The path of input dnn file to open.
  • password: Password for decrypting an encrypted dnn file.
  • is_lazy: Load the dnn file in lazy mode to save memory.

Attributes

  • affinity_masks: An affinity mask represented in hex ("0x..") or binary ("0b..") form.
  • batch_size: The number of batch size to execute forward propagation.
  • inputs: A series of DnnInput which consist of inputs of the Dnn.
  • is_dump_enabled: A flag that shows whether dumping all the tensors inside the Dnn object during forward propagation.
  • is_empty: Whether the dnn is empty or not.
  • is_lazy: Whether the dnn is lazy loaded or not.
  • is_password_protected: Whether the dnn is password-protected or not.
  • is_secret: Whether secret or not. In addition to crypto, it is hold for keeping non-secret after secret save.
  • is_tuned: Whether the dnn is tuned or not.
  • nets: A series of DnnNet objects which consist of the neural network.
  • outputs: A series of DnnOutput which consist of output of the Dnn.
  • state: The internal state of Dnn object that goes from STATE_NONE through STATE_INITIALIZED and STATE_PARSED to STATE_COMPILED.
  • tensors: A series of Tensors stored in the Dnn object.
  • thread_num: Number of threads to be used,default value is the number of cpu cores.
  • tune_params: Tuning parameters.

Examples

dnn = softneuro.Dnn('model.dnn', password)
dnn.compile()
dnn.inputs[0].set_blob(input_tensor)
dnn.forward()
output = dnn.outputs[0].blob.data

clear

Dnn.clear()

Removes all tensors and nets.


compile

Dnn.compile()

Compiles the dnn to run forward propagation.


forward

Dnn.forward()

Executes the forward propagation once on the network.


load

Dnn.load(filename, password=b"", is_lazy=False)

Reads the dnn from a file.

Arguments

  • filename: The path to the dnn file.
  • password: A password to decrypt an encrypted dnn file.
  • is_lazy: Load the dnn file in lazy mode to save memory.

parse

Dnn.parse()

Parses the dnn.


recycle

Dnn.recycle()

Recycles the dnn by decompiling and unparsing.


save

Dnn.save(filename, password=b"", is_secret=False)

Saves the dnn to a file.

Arguments

  • filename: The path to the dnn file.
  • is_secret: Save the dnn file in secret mode.
  • password: A password to encrypt the dnn file.

tune

Dnn.tune(i_recipe)

Tunes the Dnn according to DnnRecipe.

Arguments

  • i_recipe: DnnRecipe used for tuning the dnn.

Examples

import softneuro
import sys

# load a dnn.
dnn = softneuro.Dnn(sys.argv[1])

# profile.
prof = softneuro.DnnProf(dnn)
prof.add('cpu')
prof.add('cpu:qint8')
prof.profile()
prof.save('model.prof')

# optimize.
optimizer = softneuro.DnnOptimizer(prof)
optimizer.optimize()

# make recipe.
recipe = softneuro.DnnRecipe(optimizer.plan)
recipe.strip()
recipe.save('model.recipe')

# tune.
dnn.tune(recipe)
dnn.save('model_tuned.dnn')