using System.IO;using Tensorflow;using Tensorflow.Keras.Utils;using static Tensorflow.Binding;namespace TensorFlowNET.Examples{/// <summary>/// This example removes the background from an input image.////// https://github.com/susheelsk/image-background-removal/// </summary>public class ImageBackgroundRemoval : SciSharpExample, IExample{string dataDir = "deeplabv3";string modelDir = "deeplabv3_mnv2_pascal_train_aug";string modelName = "frozen_inference_graph.pb";public ExampleConfig InitConfig()=> Config = new ExampleConfig{Name = "Image Background Removal",Enabled = false,IsImportingGraph = true};public bool Run(){PrepareData();// import GraphDef from pb filevar graph = new Graph().as_default();graph.Import(Path.Join(dataDir, modelDir, modelName));Tensor output = graph.OperationByName("SemanticPredictions");using (var sess = tf.Session(graph)){// Runs inference on a single image.sess.run(output, new FeedItem(output, "[np.asarray(resized_image)]"));}return false;}public override void PrepareData(){// get mobile_net_model filestring fileName = "deeplabv3_mnv2_pascal_train_aug_2018_01_29.tar.gz";string url = $"http://download.tensorflow.org/models/{fileName}";Web.Download(url, dataDir, fileName);Compress.ExtractTGZ(Path.Join(dataDir, fileName), dataDir);// xception_model, better accuracy/*fileName = "deeplabv3_pascal_train_aug_2018_01_04.tar.gz";url = $"http://download.tensorflow.org/models/{fileName}";Web.Download(url, modelDir, fileName);Compress.ExtractTGZ(Path.Join(modelDir, fileName), modelDir);*/}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。