Comments (12)
Hi all, thank you for your support. I've tried again with a fresh project on computer B based on .NET 8.0 in a local folder and it works perfectly now. I guess the previous problem on System.NotImplementedException:
maybe because the project folder was placed in Onedrive of computer A, got synced to computer B and somehow it ends up with that error when run on computer B because some files are missing.
I also tried with .NET 6.0 as @AdrienDeverin , and it worked as well now.
Nevertheless, a new project based on .NET Framework 4.5 still has the original problem, maybe it's not supported.
from tensorflow.net.
I encountered the same problem months ago. #1017
My conclusion was that some layers (notably the Cropping layer in my case) weren't managed properly. Could you provide the model that caused the problem?
from tensorflow.net.
Hi @AdrienDeverin, I just put the exact example from the TensorFlow.NET GitHub page to try out and face this problem. I attached the code again here for easy reference, and the error occurs at the last line, which is the model.save
. I have also tried changing the save_format from "tf" to "h5" and it runs without error, but nothing was saved:
using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
using Tensorflow;
using Tensorflow.NumPy;
var layers = keras.layers;
// input layer
var inputs = keras.Input(shape: (32, 32, 3), name: "img");
// convolutional layer
var x = layers.Conv2D(32, 3, activation: "relu").Apply(inputs);
x = layers.Conv2D(64, 3, activation: "relu").Apply(x);
var block_1_output = layers.MaxPooling2D(3).Apply(x);
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(block_1_output);
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(x);
var block_2_output = layers.Add().Apply(new Tensors(x, block_1_output));
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(block_2_output);
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(x);
var block_3_output = layers.Add().Apply(new Tensors(x, block_2_output));
x = layers.Conv2D(64, 3, activation: "relu").Apply(block_3_output);
x = layers.GlobalAveragePooling2D().Apply(x);
x = layers.Dense(256, activation: "relu").Apply(x);
x = layers.Dropout(0.5f).Apply(x);
// output layer
var outputs = layers.Dense(10).Apply(x);
// build keras model
var model = keras.Model(inputs, outputs, name: "toy_resnet");
model.summary();
// compile keras model in tensorflow static graph
model.compile(optimizer: keras.optimizers.RMSprop(1e-3f),
loss: keras.losses.SparseCategoricalCrossentropy(from_logits: true),
metrics: new[] { "acc" });
// prepare dataset
var ((x_train, y_train), (x_test, y_test)) = keras.datasets.cifar10.load_data();
// normalize the input
x_train = x_train / 255.0f;
// training
model.fit(x_train[new Slice(0, 2000)], y_train[new Slice(0, 2000)],
batch_size: 64,
epochs: 10,
validation_split: 0.2f);
// save the model
model.save("./toy_resnet_model");
from tensorflow.net.
from tensorflow.net.
Thanks for your prompt response. I've tried to put a full path folder, but the problem remains.
This is what is shown in the output log:
Exception thrown: 'System.InvalidOperationException' in mscorlib.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Collection was modified; enumeration operation may not execute.
from tensorflow.net.
It's really strange. I tried it myself an no problem appear. Everything go well.
Try with this config (normally it doesn't matter, your seems good) :
- Dependancy : SciSharp.TensorFlow.Redist (2.16.0)
- directly download the Tensorflow.Net-master repo and add project Tensorflow.Keras and Tensorflow.Biding (Tensorflow.Core.sln) to your solution. Add them as reference of your test program.
My import :
using Tensorflow;
using Tensorflow.NumPy;
using Tensorflow.Keras;
using Tensorflow.Keras.Layers;
using Tensorflow.Keras.Saving;
using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Losses;
using Tensorflow.Keras.Utils;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.ArgsDefinition.Reshaping;
using Tensorflow.Operations.Activation;
using Tensorflow.Operations.Initializers;
using Tensorflow.Common.Types;
using static Tensorflow.KerasApi;
using static Tensorflow.Binding;
using static Tensorflow.ops;
using static Tensorflow.ApiDef.Types;
from tensorflow.net.
Hi, I have tried your code but I failed to reproduce it. I ran it and everything seemed to go well.
The only difference between our code is that I changed epoch to 1 and batch to 4 to make it faster to complete the training. I guess that doesn't matter.
P.S. I was using the CPU redist package.
from tensorflow.net.
Hi @AdrienDeverin and @AsakusaRinne, thank you both for your help. Let me explain what exactly happened: I have 2 computers, A and B. I started trying the example code on computer A, where I created a new project with .NET Framework 4.8. Then I faced the problem described at the beginning. I tried different stuff as suggested by @AdrienDeverin but it didn't solve the problem. Later on, I created a new project based on .NET 8.0 on computer A, and it worked like a charm. I tried to replicate the solution on computer B, also with .NET 8 and all the same Nuget packages installed. It now gives me a different error on the model.save
:
System.NotImplementedException: ''
Have you experienced this before? This is pretty confusing for me.
Ps: this is the project properties for your reference. I'm using VS2022 V17.9.6
from tensorflow.net.
I didn't manage to reproduce it on my PC. Could you please clone the repo and add project reference to it, so that a detailed trace back will be shown?
from tensorflow.net.
Me too, I tried to reproduce your bug, but it's working correctly on my computer... :/
(To add more, I was testing it in .NET 6.0)
Another idea to understand where the problem lies: since you have done what I said earlier, you could use the debug mode and see in the code step by step where you go (and compare with computer A)...
from tensorflow.net.
Nevertheless, a new project based on .NET Framework 4.5 still has the original problem, maybe it's not supported.
It's expected to support .NET framework 4.5. Could you please run with the tf.net repo and put the detailed traceback here if you'd like to dig on it?
from tensorflow.net.
I was figuring out a solution to make .NET Framework-based app work, but not sure if this is a bug or anything. Let me detail the process so that someone facing the same issue knows how to get through it.
The original problem was:
- I created a new c# winform app using .NET Framework 4.8, and set it to work with x64 only.
- Installed nuget packages: TensorFlow.NET, SciSharp.TensorFlow.Redist, and TensorFlow.Keras. To successfully install TensorFlow.Keras, I needed to install the PureHDF separately first (by checking the Include prerelease).
- Copy the example from the main SciSharp github page
- Copy the tensorflow.dll from SciSharp.TensorFlow.Redist.2.16.0 package into the debug folder (to clear the backend not found exception)
- Got the System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' at the
model.save
How did I get it work:
- Download the entire TensorFlow.Net repo -> create a new .NET Framework 4.8 project within the TensorFlow.NET solution.
- Installed nuget packages: TensorFlow.NET, SciSharp.TensorFlow.Redist, and TensorFlow.Keras. This is to get all the dependencies to be installed. After that, uninstall TensorFlow.NET and TensorFlow.Keras.
- Copy the tensorflow.dll into the debug folder
- In my project, add a reference to the Tensorflow.Binding and Tensorflow.Keras from the repo.
- The application works smoothly now without error.
When I checked the output debug folder, I noticed the size difference in the Tensorflow.Binding.dll and Tensorflow.Keras.dll between the original and the solution. Copying these two files from the updated solution folder to the previous project folder solve the error too. Thus, I guess there should be some differences in the Tensorflow.Binding.dll and Tensorflow.Keras.dll between the release NuGet packages and the repo. Do you have any idea on this @AsakusaRinne?
from tensorflow.net.
Related Issues (20)
- tensorflow.keras is missing NuGet package README file
- [BUG Report]: Cannot find backend on Apple Silicon mac HOT 1
- [Question]: How to use regularizer ?
- Error when running model.fit after upgrade tensorflow.net to v0.150 HOT 1
- [BUG Report]: EarlyStopping Callback Stops Training Prematurely Regardless of Performance Improvement
- [Feature Request]: TimeDistributed and Dot
- [Performance Issue]: 125x performance difference between Python and TensorFlow.NET HOT 5
- [Question]: How to achieve glass breakage detection
- System.Collections.Generic.KeyNotFoundException: The given key '1' was not present in the dictionary. HOT 1
- There is no method jacobian() in tf.GradientTape class?
- [Performance Issue]: Model Convergence issue in Keras with Parallel Execution of the fit() Method ? HOT 7
- Deserialization exception thrown when loading a Keras SavedModel HOT 18
- [BUG Report]: Tensorflow.RuntimeError: Tensorflow.NET cannot find a backend despite having installed SciSharp.TensorFlow.Redist on macOS M1 HOT 3
- [BUG Report]: load_weights fails to open HDF5 file
- TensorBoard接入
- tensorflow.dll
- 搞个微信群吧
- Microsoft.ML.TensorFlow和TensorFlow.NET到底啥关系?
- TensorFlow Serving
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorflow.net.