SciSharp / TensorFlow.NET

.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
https://scisharp.github.io/tensorflow-net-docs
Apache License 2.0
3.23k stars 517 forks source link

Example of 'Transfer Learning' on multiple layers with TensorFlow.NET #248

Open CESARDELATORRE opened 5 years ago

CESARDELATORRE commented 5 years ago

I was checking out the TensofFlow samples available in the repo but looks like in all of them (Image Classification, Object Detection) the samples are just running/scoring pre-trained TensorFlow models such as Inception v3:

https://github.com/SciSharp/TensorFlow.NET/blob/master/test/TensorFlowNET.Examples/ImageProcess/ImageRecognitionInception.cs

https://github.com/SciSharp/TensorFlow.NET/blob/master/test/TensorFlowNET.Examples/ImageProcess/InceptionArchGoogLeNet.cs

https://github.com/SciSharp/TensorFlow.NET/blob/master/test/TensorFlowNET.Examples/ImageProcess/ObjectDetection.cs

Do you support more advanced scenarios such as:

Do you have (is it possible with TensorFlow.NET?) any example on how to do 'Transfer Learning' with TensorFlow.NET such as training with new images on the final layer and even on multiple layers (and ultimately possibility for the full network) of the TF network?

The following is a basic 'Transfer Learning' sample using Keras/Python.

https://github.com/dotnet-architecture/eShopOnContainersAI/blob/dev/workbench/keras_training.py

I mean something comparable to that but using TensorFlow.NET.

Thanks! :)

Oceania2018 commented 5 years ago

@CESARDELATORRE Absolutly tf.net can train and predict image. I'll try my best to do an example for your case and upload to Example project. Please check the RetrainImageClassifier example. It's not finished yet currently.

Oceania2018 commented 5 years ago

@CESARDELATORRE The Transfer Learning example is finished. Let me know if you have any question.

CESARDELATORRE commented 5 years ago

@Oceania2018 - Cool! - I'll learn about it as soon as possible! Btw, I was just testing the samples and it gave me an error/exception in VS when running the samples, here:

image

System.Exception HResult=0x80131500 Message=SemanticPredictions:0 is both fed and fetched. Source=TensorFlow.NET StackTrace: at Tensorflow.Status.Check(Boolean throwException) in D:\GitRepos\TensorFlow.NET\src\TensorFlowNET.Core\Status\Status.cs:line 48 at Tensorflow.BaseSession._call_tf_sessionrun(KeyValuePair2[] feed_dict, TF_Output[] fetch_list, List1 target_list) in D:\GitRepos\TensorFlow.NET\src\TensorFlowNET.Core\Sessions\BaseSession.cs:line 214 at Tensorflow.BaseSession._do_run(List1 target_list, List1 fetch_list, Dictionary2 feed_dict) in D:\GitRepos\TensorFlow.NET\src\TensorFlowNET.Core\Sessions\BaseSession.cs:line 189 at Tensorflow.BaseSession._run(Object fetches, FeedItem[] feed_dict) in D:\GitRepos\TensorFlow.NET\src\TensorFlowNET.Core\Sessions\BaseSession.cs:line 142 at Tensorflow.BaseSession.run(Object fetches, FeedItem[] feed_dict) in D:\GitRepos\TensorFlow.NET\src\TensorFlowNET.Core\Sessions\BaseSession.cs:line 45 at TensorFlowNET.Examples.ImageProcess.ImageBackgroundRemoval.<>c__DisplayClass15_0.<Run>b__0(Session sess) in D:\GitRepos\TensorFlow.NET\test\TensorFlowNET.Examples\ImageProcess\ImageBackgroundRemoval.cs:line 42 at Tensorflow.Python.with[T](T py, Action1 action) in D:\GitRepos\TensorFlow.NET\src\TensorFlowNET.Core\Python.cs:line 88

Oceania2018 commented 5 years ago

Seems like you’re running a unfinished example: TensorFlowNET.Examples.ImageProcess.ImageBackgroundRemoval.

CESARDELATORRE commented 5 years ago

I'm running the whole project from VS. It'd be good to either split the samples or to comment the call invoking a sample that is not finished?

Oceania2018 commented 5 years ago

Check this file: https://github.com/SciSharp/TensorFlow.NET/blob/master/test/TensorFlowNET.Examples/Program.cs, you can pass example.Name to run specific example only.

PranovD commented 5 years ago

image File RetrainImageClassifier.cs Line 362

I am getting an error about InceptionV3.meta not being loadable due to mismatched attributes. I believe this is a issue with using InceptionV3.meta on any version of TensorFlow higher than 1.4 (I am using 1.13 from the documentation), do you know of a work around?

https://github.com/tensorflow/models/issues/4093