migueldeicaza / TensorFlowSharp

TensorFlow API for .NET languages
MIT License
3.14k stars 578 forks source link

Darkflow model (YOLO) on Tensorflowsharp #215

Open IlSaCCo opened 6 years ago

IlSaCCo commented 6 years ago

I am having some problem with my object detection project. It works when I retrain a model from tensorflow zoo. I am trying to get faster detection and I wanted to experiment with YOLO model.

I am using darkflow for having YOLO working with Tensorflow. I trained my model on my custom dataset. then I froze it using the instruction on the darkflow page. I now have my PB file and a metafile, so far so good.

I then adjusted my code in the tensorflowsharp project, pointing to the just created protobuf and adapted the name of the input output variables, from:

String[] outputs = { "detection_boxes:0", "detection_scores:0", "detection_classes:0", "num_detections:0" }; runner.AddInput("image_tensor:0", tensor).Fetch(outputs); try { output = runner.Run(); } catch (TFException e) { Console.WriteLine(e.ToString()); }

to:

runner.AddInput("input:0", tensor).Fetch("output:0"); try { output = runner.Run(); } catch (TFException e) { Console.WriteLine(e.ToString()); } Following the name of the variables in the darkflow documentation. I am able to add input and output pointer to the session but when I get to run the detection (Runner.Run) I get the exception:

TensorFlow.TFException: Expects arg[0] to be float but uint8 is provided Runner.Run() returns null.

I am not sure what the name of the output tensors are in darkflow, on the documentation I found:

The name of input tensor and output tensor are respectively 'input' and 'output'. For further usage of this protobuf file, please refer to the official documentation of Tensorflow on C++ API here.

but I would expect different collection (tensors) as return type as it is for SSD and other models, right?

Thanks

Nyoden commented 6 years ago

You could check the existing layers from a loaded graph by using a LINQ Query on the graph object.

Lets say you have something like that :

using (TFSession DataSession = new TFSession()){

Byte[] modelfiledata = File.ReadAllBytes(pathtomodelfile);
DataSession.Graph.Import(modelfiledata, "");

var Layers = DataSession.Graph.GetEnumerator().Select(x=>x.Name)
}

From there you could check the names of layers. With keras models (converted to pb) i remember them beeing input_1 instead of input and my outputlayer that i named final_result ended up beeing final_result/Softmax so maybe there are similar things happening with yolo models.

btw. Did you have a look at YoloSharp ?

IlSaCCo commented 6 years ago

Hey Nyoden,

thanks for your reply, no I didn't check YoloSharp, good call! I will definitely have a look at it!

Thanks

Nyoden commented 6 years ago

You are welcome! Iam using YoloSharp in combination with the pretrained (tinyolo) and it works fine.(besides being a bit on the slow side)

IlSaCCo commented 6 years ago

How many fps are you able to get?

2018-02-19 12:53 GMT+01:00 Nyoden notifications@github.com:

You are welcome! Iam using YoloSharp in combination with the pretrained (tinyolo) and it works fine.(besides being a bit on the slow side)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/migueldeicaza/TensorFlowSharp/issues/215#issuecomment-366667511, or mute the thread https://github.com/notifications/unsubscribe-auth/AGaPr5GE5H__k89hbosFo3d62Rql8Cv5ks5tWWCegaJpZM4Rp9f_ .

Nyoden commented 6 years ago

Iam getting around 8-11 fps (on a Xeon 6Core/12Thread + 980ti) but iam not using it on a videostream so i think there is a lot room for optimization. At the moment iam using it to "batch-tag" a folder of images within a simple loop and calling .Detect() multiple times.

Amanpradhan commented 5 years ago

Hey @Nyoden and @IlSaCCo , I am also doing something similar and I'd like to detect custom objects using yolo. Can any one of you help me in regard of what do I need to do?