我正在尝试使用tensorflow.net将工作的pythonxor示例转换为c绑定
我在vs代码中测试的工作python代码如下:
import numpy as np
from keras.models import Sequential
from keras.layers.core import Activation, Dense
training_data = np.array([[0,0],[0,1],[1,0],[1,1]], "float32")
target_data = np.array([[0],[1],[1],[0]], "float32")
model = Sequential()
model.add(Dense(32, input_dim=2, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['binary_accuracy'])
model.fit(training_data, target_data, epochs=100, verbose=2)
print(model.predict(training_data))
我对tensorflow.net绑定的c#翻译如下:
using System;
using NumSharp;
using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
var trainingData = np.array((Array) new float[,] {{0, 0}, {0, 1}, {1, 0}, {1, 1}});
var targetData = np.array((Array) new float[,] {{0}, {1}, {1}, {0}});
var model = keras.Sequential();
model.add(keras.Input(2)); // NOTE: based on debugging this will be shape [None, 2] in the C# binding
model.add(keras.layers.Dense(32, keras.activations.Relu));
model.add(keras.layers.Dense(1, keras.activations.Sigmoid));
model.compile(keras.losses.MeanSquaredError(), keras.optimizers.Adam(), new[] {"accuracy"}); // binary_accuracy is not implemented yet in the C# binding
model.fit(trainingData, targetData, 4, 100, 2); // batch_size = 4, epochs = 100, verbose = 2
print(model.predict(trainingData));
但是,在执行model.fit()时
tensorflow.stopiteration:tensorflow.keras.engine.model的tensorflow.OwnEditor.next()处的序列结束。在tensorflow.keras.engine.model.predict(tensor x,int32 batch\u size,int32 verbose,int32 steps,int32 max\u queue\u size,int32 workers,boolean use\u multiprocessing)处运行\u predict\u步骤(OwnEditor迭代器)
暂无答案!
目前还没有任何答案,快来回答吧!