Comments (3)
Hello, could you mind providing your version of TensorFlow.NET? And how do you save and load model (we recommend to use keras.models.load_model to load the whole model rather than save and load weight, because it has a more comprehensive implementation)? I use the following code to save model, then load it and predict it twice, and it works well. (The version of my TensorFlow.NET and TensorFlow.Keras is 0.110.4)
using static Tensorflow.KerasApi;
using Tensorflow;
var input = keras.Input((784));
var x = keras.layers.Reshape((28, 28)).Apply(input);
x = keras.layers.LSTM(50, return_sequences: true).Apply(x);
x = keras.layers.LSTM(100).Apply(x);
var output = keras.layers.Dense(10, activation: "softmax").Apply(x);
var model = keras.Model(input, output);
model.summary();
model.compile(keras.optimizers.Adam(), keras.losses.CategoricalCrossentropy(), new string[] { "accuracy" });
var data_loader = new MnistModelLoader();
var dataset = data_loader.LoadAsync(new ModelLoadSetting
{
TrainDir = "mnist",
OneHot = true,
ValidationSize = 55000,
}).Result;
model.fit(dataset.Train.Data, dataset.Train.Labels, batch_size: 16, epochs: 1);
model.save("./mnist_model");
// after training and saving model, comment the code above and uncomment the following code.
//var model = keras.models.load_model("./mnist_model");
//var input = tf.ones((8, 28, 28), dtype: TF_DataType.TF_FLOAT);
//var output = model.predict(input, 4);
//Console.WriteLine(output.numpy().ToString());
from tensorflow.net.
I use a version 0.150.0.
Predict it twice I mean like this:
model.fit(dataset.Train.Data, dataset.Train.Labels, batch_size: 64, epochs: 1);
(x_test, y_test) = (dataset.Test.Data, dataset.Test.Labels);
var output = model.predict(x_test, , use_multiprocessing: true, workers: 8);
model.save("./mnist_model");
model.save_weights("./Weights");
keras.backend.clear_session();
model = keras.models.load_model("./mnist_model");
model.load_weights("./Weights");
output = model.predict(x_test, , use_multiprocessing: true, workers: 8);
keras.backend.clear_session();
model = keras.models.load_model("./mnist_model");
model.load_weights("./Weights");
output = model.predict(x_test, , use_multiprocessing: true, workers: 8);
Without the weights two predictions of same inputs do not match.
from tensorflow.net.
Hello, could you please try use version 0.110.4 for now? I run the code you provided above in version 0.110.4, it runs well, and it fails when in version 0.150.0.
from tensorflow.net.
Related Issues (20)
- [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
- Error when saving model using model.save HOT 12
- 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 5
- [BUG Report]: load_weights fails to open HDF5 file
- TensorBoard接入
- tensorflow.dll
- 搞个微信群吧
- Microsoft.ML.TensorFlow和TensorFlow.NET到底啥关系?
- TensorFlow Serving
- [Question]: Can now work the TextVectorization method? HOT 1
- When will TF 2.16 be updated?
- [BUG Report]: GPU LSTM,erro:System.EntryPointNotFoundException:“Unable to find an entry point named 'TF_GetHandleShapeAndType' in DLL 'tensorflow'.” HOT 1
- [Performance Issue]: h.5 isn't supported HOT 5
- Error loading or saving model
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.