I want to upgrade from Sentic 1.4 to Sentic 2.1.1, but I have encountered a problem. I don’t know how to write these codes in version Sentic 2.1.1. I hope to receive some help, thanks.
code 1:
var editedModel = Functional.Compile(
RGB =>
{
var sRGB = Functional.Pow(RGB, Functional.Tensor(1 / 2.2f));
// Transform values from the range [0, 1] to the range [0, 255].
var RGB_255 = Functional.Mul(sRGB, Functional.Tensor(255.0f));
return nnmodel.ForwardWithCopy(RGB_255)[0];
},
nnmodel.inputs[0]);
code 2:
var output = _worker.PeekOutput(_config.OutputName) as TensorFloat;
output.CompleteOperationsAndDownload();
_detections = output.ToReadOnlyArray();
Hi Zeng,
For code 1, please use FunctionalGraph and the Functional api. There are examples in this discussion, and in this page.
For code 2, something like this:
var output = _worker.PeekOutput(_config.OutputName) as Tensor<float>;
_detections = output.ReadbackAndClone();
Let us know if you need more details.
Viviane
Hi Viviane
Thank you for your reply.
The purpose of writing these codes is to use movenet. I tried to make some modifications according to the official documentation, but the code did not work.
Original code:
// NN model loading
var nnmodel = ModelLoader.Load(resources.model);
// Edit a Model
var editedModel = Functional.Compile(
RGB =>
{
var sRGB = Functional.Pow(RGB, Functional.Tensor(1 / 2.2f));
// Transform values from the range [0, 1] to the range [0, 255].
var RGB_255 = Functional.Mul(sRGB, Functional.Tensor(255.0f));
return nnmodel.ForwardWithCopy(RGB_255)[0];
},
nnmodel.inputs[0]);
// Private object initialization
_resources = resources;
_config = new Config(editedModel);
_worker = WorkerFactory.CreateWorker(BackendType.GPUCompute, editedModel);
Modified code:
// NN model loading
var nnmodel = ModelLoader.Load(resources.model);
// Edit a Model
var graph = new FunctionalGraph();
var RGB = graph.AddInput(nnmodel, 0);
var sRGB = Functional.Pow(RGB, Functional.Constant(1 / 2.2f));
var RGB_255 = Functional.Mul(sRGB, Functional.Constant(255.0f));
var sRGB_normalised = sRGB * 2 - 1;
var outputs = Functional.Forward(nnmodel, sRGB_normalised)[0];
var editedModel = graph.Compile(outputs[0]);
// Private object initialization
_resources = resources;
_config = new Config(editedModel);
//_worker = WorkerFactory.CreateWorker(BackendType.GPUCompute, editedModel);
_worker = new Worker(editedModel, BackendType.GPUCompute);
I found this example here https://github.com/Yupopyoi/MoveNet-UnitySentis/blob/main/Assets/Scripts/MoveNet/Detector/Detector.cs and I want to use it.
Thanks
Zeng
Hi Zeng,
Thank you for the additional information! We will take a look.
Have a nice day,
Viviane
Hi Zeng,
The code looks good, it probably needs some fine tuning.
I observed that the value RGB_255
is computed but not used.
Do you want to write var outputs = Functional.Forward(nnmodel, RGB_255);
?
Other than that, I see no issue. You may want to debug and look at the inputs, outputs and tensors at each step to ensure the data is as expected. More info
Please refer to How to upgrade from older Sentis versions to version 2.1 for functions that have changed.
I hope this helps.
Viviane
Thank you, Viviane, Merry Christmas!