Skip to content

[BUG Report]: Tensorflow.Numpy.NDArray handling exception with .NET 4.8 #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abrguyt opened this issue Jan 31, 2025 · 1 comment
Closed

Comments

@abrguyt
Copy link

abrguyt commented Jan 31, 2025

Description

Using .NET 4.8 and the latest nightly (Tensorflow.Keras 0.150.0-BERT-Model-46-g6a2d7e1c-nightly) and simply preparing Tensorflow.NumPy.NDArray data objects for Keras model fitting; it seems NDArray objects are created whose contents cannot be read properly:

float[] floatArray = [1f, 1.1f, 1.11f, 2f, 2.2f, 2.22f];

var targetShape = new Tensorflow.Shape(2, 3);

var tf_nd_array = new Tensorflow.NumPy.NDArray(floatArray, targetShape);

// simply reading value from row 0, column 0 will result in an exception
var value = tf_nd_array[0, 0];

The exception thrown when a value is read from the NDArray object is:

The type initializer for 'OnMethodBoundaryAspectCompile.MethodInfos' threw an exception.
Inner Exception:
FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

This exception seems related to the NuGet 'MethodBoundaryAspect.Fody' dependency and a reference to .NET 8, while this all is running under .NET 4.8.

Can anyone confirm what the last version of Tensorflow.Keras is that can run on .NET 4.8 ?

Reproduction Steps

No response

Known Workarounds

No response

Configuration and Other Information

Tensorflow.Keras 0.150.0-BERT-Model-46-g6a2d7e1c-nightly
.NET 4.8
Windows 10

@abrguyt
Copy link
Author

abrguyt commented Feb 4, 2025

I reverted back to just using the 'official' latest Tensorflow.Keras v. 0.15 which doesn't have this issue.

There is one other problem though with the NuGet Tensorflow.Keras v. 0.15 / Tensorflow.NET v 0.150 versions - model.save() does not work and results in an error under .NET 4.8.

However as suggested by https://github.com/SciSharp/TensorFlow.NET/issues/1246#issuecomment-2134968838 just downloading the Github Repo and building and/or repackaging yourself solve this model.save() issue - somehow the DLL files produced when doing a custom build results in different DLL files from those available on NuGet.

So now I got it all working with (custom) packaged Tensorflow.Keras v. 0.15 and .NET 4.8 - thanks for very valuable input on this forum.

@abrguyt abrguyt closed this as completed Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant