Skip to content

[BUG Report]: saving model in MacOS fails #1273

Open
@thomasd3

Description

@thomasd3

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_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions