使用Unity Sentis 实现无绿幕AI抠图

使用Sentis 实现实时无绿幕抠图。

模型分析:

输入值为256*144*3的图片,输出值为256*144的单通道遮罩图;

代码示例:

  var input = TextureConverter.ToTensor(source, 256, 144, 3);   
             
         TensorFloat _2 = new TensorFloat(2f);
         TensorFloat _1 = new TensorFloat(1f);
         
        TensorFloat input1 = TensorFloat.AllocZeros(_3_144_256);
        gpu.Mul(input,_2,input1); 
        
        TensorFloat input2 = TensorFloat.AllocZeros(_3_144_256);
        gpu.Sub(input1,_1,input2); 
        
        var input3 = TensorFloat.AllocNoData(_144_256_3);
  
        gpu.Transpose(input2,input3,new [] {0,2,3,1}); 
        worker.Execute(input3);
          
        _1.Dispose();
        _2.Dispose();
        input.Dispose();
        input1.Dispose();
        input2.Dispose();
        input3.Dispose(); 
      
        using var output = worker.PeekOutput("segment_back") as TensorFloat; 

猜你喜欢

转载自blog.csdn.net/m0_55632444/article/details/139521069