|
|
@@ -1,7 +1,10 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.IO; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
|
|
|
using Tensorflow; |
|
|
using TensorFlowNET.Examples.Utility; |
|
|
using TensorFlowNET.Examples.Utility; |
|
|
|
|
|
using static Tensorflow.Python; |
|
|
|
|
|
|
|
|
namespace TensorFlowNET.Examples.ImageProcess |
|
|
namespace TensorFlowNET.Examples.ImageProcess |
|
|
{ |
|
|
{ |
|
|
@@ -19,18 +22,42 @@ namespace TensorFlowNET.Examples.ImageProcess |
|
|
|
|
|
|
|
|
public string Name => "Image Background Removal"; |
|
|
public string Name => "Image Background Removal"; |
|
|
|
|
|
|
|
|
string modelDir = "deeplabv3"; |
|
|
|
|
|
|
|
|
string dataDir = "deeplabv3"; |
|
|
|
|
|
string modelDir = "deeplabv3_mnv2_pascal_train_aug"; |
|
|
|
|
|
string modelName = "frozen_inference_graph.pb"; |
|
|
|
|
|
|
|
|
public bool Run() |
|
|
public bool Run() |
|
|
{ |
|
|
{ |
|
|
|
|
|
PrepareData(); |
|
|
|
|
|
|
|
|
|
|
|
// import GraphDef from pb file |
|
|
|
|
|
var graph = new Graph().as_default(); |
|
|
|
|
|
graph.Import(Path.Join(dataDir, modelDir, modelName)); |
|
|
|
|
|
|
|
|
|
|
|
Tensor output = graph.OperationByName("SemanticPredictions"); |
|
|
|
|
|
|
|
|
|
|
|
with(tf.Session(graph), sess => |
|
|
|
|
|
{ |
|
|
|
|
|
// Runs inference on a single image. |
|
|
|
|
|
sess.run(output, new FeedItem(output, "[np.asarray(resized_image)]")); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void PrepareData() |
|
|
public void PrepareData() |
|
|
{ |
|
|
{ |
|
|
// get model file |
|
|
|
|
|
string url = "http://download.tensorflow.org/models/deeplabv3_mnv2_pascal_train_aug_2018_01_29.tar.gz"; |
|
|
|
|
|
Web.Download(url, modelDir, "deeplabv3_mnv2_pascal_train_aug_2018_01_29.tar.gz"); |
|
|
|
|
|
|
|
|
// get mobile_net_model file |
|
|
|
|
|
string 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);*/ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |