JuliaIO / BSON.jl

Other
157 stars 39 forks source link

support non-dict fileio_save args #36

Closed johnnychen94 closed 4 years ago

johnnychen94 commented 5 years ago

Continue #31 The idea is quite simple: create a dummy name for each input and wrap them into a Dict. ( I didn't know BSON data should be represented by a Dict until I check this repo)

This makes save("model.bson", model)-kind usage works instead of throwing MethodError.

An alternative is to print more descriptive error message than

julia > FileIO.save("mymodel.bson", model)
Error encountered while saving "mymodel.bson".
Fatal error:
ERROR: MethodError: no method matching fileio_save(::File{DataFormat{:BSON}}, ::Chain{Tuple{Dense{typeof(relu),TrackedArray{…,Array{Float32,2}},TrackedArray{…,Array{Float32,1}}},Dense{typeof(identity),TrackedArray{…,Array{Float32,2}},TrackedArray{…,Array{Float32,1}}},typeof(softmax)}})
Closest candidates are:
  fileio_save(::Any, ::AbstractDict) at /home/math/jc/.julia/packages/BSON/XPZLD/src/fileio_interface.jl:3
  fileio_save(::Any, ::Pair...) at /home/math/jc/.julia/packages/BSON/XPZLD/src/fileio_interface.jl:4