Skip to content

Bad results of simple XOR training #952

Closed
@neojg

Description

@neojg

I have windows 10 CPU with:

Python 3.9.13
tensorflow 2.10.0

I'm testing a simple XOR training:

            var x = np.array(new float[,] { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } });
            var y = np.array(new float[,] { { 0 }, { 1 }, { 1 }, { 0 } });

            var model = keras.Sequential();
            model.add(keras.Input(2));
            model.add(keras.layers.Dense(32, keras.activations.Relu)); // 
            model.add(keras.layers.Dense(64, keras.activations.Relu));
            model.add(keras.layers.Dense(1, keras.activations.Sigmoid));
            model.compile(keras.optimizers.Adam(), keras.losses.MeanSquaredError(), new[] { "accuracy" });
            model.fit(x, y, epochs: 800, verbose: 2);
            print(model.predict(x, 4));

The results from print command are as follow:

tf.Tensor: shape=(4, 1), dtype=float32, numpy=array([[0,5],
[0,492741],
[0,4584209],
[0,4671426]])

PROBLEM

  1. When I run same sample on python/keras all is OK
  2. The console does not show the training messages!
  3. The c# results are incorrect!

What is wrong? Is there a way to get simmilar results for python/tensorflow/keras and the Tensorflow.Net?

Metadata

Metadata

Labels

bugSomething isn't workingdiscussionA topic needed to discuss

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions