TensorFlow.NET icon indicating copy to clipboard operation
TensorFlow.NET copied to clipboard

[BUG Report]: saving model in MacOS fails

Open thomasd3 opened this issue 1 year ago • 0 comments

Description

I'm on MacOS (Intel), and saving a model causes the save function to fail as it's missing a library.

Reproduction Steps

Here is the F# port of the XOR sample code:

open Microsoft.FSharp.Collections
open Tensorflow
open Tensorflow.NumPy
type tf = KerasApi



[<EntryPoint>]
let main argv =
    let dx = array2D [| [| 0.0f; 0.0f |]; [| 0.0f; 1.0f |]; [| 1.0f; 0.0f |]; [| 1.0f; 1.0f |] |]
    let x = np.array(dx)

    let dy = array2D [| [| 0.0f |]; [| 1.0f |]; [| 1.0f |]; [| 0.0f |] |]
    let y = np.array(dy)

    let model = tf.keras.Sequential()
    model.add(tf.keras.Input(2))
    model.add(tf.keras.layers.Dense(32, tf.keras.activations.Relu))
    model.add(tf.keras.layers.Dense(1, tf.keras.activations.Sigmoid))

    model.compile(optimizer = tf.keras.optimizers.Adam(), loss = tf.keras.losses.MeanSquaredError(), metrics = [| "accuracy" |])
    model.fit(x, y, batch_size = 4, epochs = 200, use_multiprocessing = true) |> ignore
    let d = model.evaluate(x, y)
    let result = model.predict(x, 4)


    model.save_weights("test-weights.model")
    model.save("test.model")
    0

The libraries included in the project are:

    <ItemGroup>
      <PackageReference Include="SciSharp.Models.TimeSeries" Version="0.9.0" />
      <PackageReference Include="SciSharp.TensorFlow.Redist-OSX" Version="2.15.0" Condition="'$(Configuration)'!='GPU'" />
      <PackageReference Include="TensorFlow.Keras" Version="0.15.0" />
      <PackageReference Update="FSharp.Core" Version="8.0.401" />
    </ItemGroup>

Both save calls give this error:

System.TypeInitializationException: The type initializer for 'HDF.PInvoke.H5T' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'HDF.PInvoke.H5DLLImporter' threw an exception.
 ---> System.IO.FileNotFoundException: /Users/USER/*/libhdf5.dylib```

### Known Workarounds

_No response_

### Configuration and Other Information

_No response_

thomasd3 avatar Oct 24 '24 02:10 thomasd3