-
Notifications
You must be signed in to change notification settings - Fork 156
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
Unable to retrieve saved machines #743
Comments
Mmm, that's frustrating. Thanks for reporting. This sounds to me like a serialization issue, rather than something specific to MLJ. So you may get more help by posting an issue at JLSO.jl or on Julia discourse. cc @oxinabox . I can tell you that:
using MLJ
X, y = @load_iris;
model = (@load DecisionTreeClassifier)()
mach = machine(model, X, y) |> fit!
MLJ.save("junk.jlso", mach)
using JLSO
jlso = JLSO.read("junk.jlso", JLSOFile);
jlso.julia
jlso.manifest
So if this works for your file, you should be able to reproduce your environment to the state at save time. |
Should load up an environment with exactly the dependencies you had loaded before. There is also an open issue, and an inlcuded hacky method and a PR for a less hacky method to also load the packages. |
Thank you both for your attention, but none of the things suggested seems to work. Perhaps sharing one of the .jlso files I am unable to retrieve helps? GitHub doesn't support files of this type, so I got a Wetransfer link: And here is the code I am using to try to retrieve my saved machines (the code is a bit longer because I am stacking models and the learning network has to be defined and exported first), which works with a newly saved machine but not the file above. using MLJ
using EvoTrees
using DataFrames
# Define learning network
begin
# source nodes
X = source()
y = source()
# node 1
logmodel = (@load LogisticClassifier pkg=MLJLinearModels)()
log = machine(logmodel, X, y)
LOG = predict(log, X)
# node 2
evomodel = (@load EvoTreeClassifier)()
evo = machine(evomodel, X, y)
EVO = predict(evo, X)
# define new model type for node 3
mutable struct Compiler <: Static
end
# and its transform method
import MLJBase
function MLJBase.transform(c::Compiler,_,y1, y2)
prob_y1 = pdf.(y1, 1)
prob_y2 = pdf.(y2, 1)
X_stack = DataFrame(:Prob_1_LOG => prob_y1, :Prob_1_EVO => prob_y2)
return X_stack
end
# node 3
compiler = Compiler()
comp= machine(compiler)
X_stack = MLJ.transform(comp, LOG, EVO)
# node 4
metamodel = (@load LogisticClassifier pkg=MLJLinearModels)()
meta = machine(metamodel, X_stack, y)
META = predict(meta, X_stack)
end
# Export as a new model type
mach = machine(Probabilistic(), X, y; predict = META)
@from_network mach begin
mutable struct CompositeModel
model1 = logmodel
model2 = evomodel
compiler = compiler
judge = metamodel
end
end
# Fit and save a machine
begin
X = rand(100, 10)
y = coerce(rand([0, 1], 100), OrderedFactor)
mymodel = CompositeModel()
mymach = machine(mymodel, X_train, y_train) |> fit!
MLJ.save("junk.jlso", mymach)
end
# Retrieve new and old machines
success = machine("junk.jlso", X_train, y_train)
fail = machine("model1_trained_Run1.jlso", X_train, y_train)
# Trying what was suggested here
using JLSO
jlso_success = JLSO.read("junk.jlso", JLSOFile)
jlso_success.julia
jlso_success.manifest
jlso_fail = JLSO.read("model1_trained_Run1.jlso", JLSOFile)
jlso_fail.julia
jlso_fail.manifest
#note that the number of packages in each manifest is different
using Pkg
Pkg.activate(jlso_fail)
still_fails = machine("model1_trained_Run1.jlso", X, y)
Pkg.activate(jlso_success)
still_fails = machine("model1_trained_Run1.jlso", X, y)
# Trying the trick from the other issue
eval(Expr(:using, (Expr(:., n) for n in Symbol.(keys(Pkg.Types.Context().env.project.deps)))...))
still_fails = machine("model1_trained_Run1.jlso", X, y) Any ideas? |
Additional Context More information at julia-vscode/julia-vscode#1967 |
Did you run |
Sorry, I'm not sure of what you mean |
I went to a plain REPL and after doing Pkg.add JLSO
using JLSO
using Pkg Then I defined the learning network, exported it and created the variables X and y with the code I shared in my previous post. To do this, I needed to jlso_fail = JLSO.read("model1_trained_Run1.jlso", JLSOFile) #copied file into pwd()
Pkg.activate(jlso_fail)
still_fails = machine("model1_trained_Run1.jlso", X, y) I got the following error, a bit different this time: [warn | JLSO]: KeyError: key MLJGLMInterface [caf8df21-4939-456d-ac9c-5fefbfb04c0c] not found
[warn | JLSO]: KeyError: key MLJGLMInterface [caf8df21-4939-456d-ac9c-5fefbfb04c0c] not found
[warn | JLSO]: KeyError: key MLJGLMInterface [caf8df21-4939-456d-ac9c-5fefbfb04c0c] not found
ERROR: MethodError: no method matching machine(::Array{UInt8,1}, ::Array{Float64,2}, ::CategoricalArrays.CategoricalArray{Int64,1,UInt32,Int64,CategoricalArrays.CategoricalValue{Int64,UInt32},Union{}})
Closest candidates are:
machine(::Type{#s41} where #s41<:MLJModelInterface.Model, ::Any...) at C:\Users\ivica\.julia\packages\MLJBase\fYEbE\src\machines.jl:203
machine(::Static, ::Any...) at C:\Users\ivica\.julia\packages\MLJBase\fYEbE\src\machines.jl:213
machine(::MLJModelInterface.Model, ::Any, ::Any...) at C:\Users\ivica\.julia\packages\MLJBase\fYEbE\src\machines.jl:231
...
Stacktrace:
[1] machine(::String, ::Array{Float64,2}, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\ivica\.julia\packages\MLJBase\fYEbE\src\machines.jl:702
[2] machine(::String, ::Array{Float64,2}, ::CategoricalArrays.CategoricalArray{Int64,1,UInt32,Int64,CategoricalArrays.CategoricalValue{Int64,UInt32},Union{}}) at C:\Users\ivica\.julia\packages\MLJBase\fYEbE\src\machines.jl:694
[3] top-level scope at REPL[26]:1 I did [warn | JLSO]: KeyError: key DataFrames [a93c6f00-e57d-5684-b7b6-d8193f3e46c0] not found
Machine{ProbabilisticTunedModel{RandomSearch,…}} @602 trained 1 time.
args:
1: Source @074 ⏎ `AbstractArray{Continuous,2}`
2: Source @801 ⏎ `AbstractArray{OrderedFactor{2},1}` Which after doing Machine{ProbabilisticTunedModel{RandomSearch,…}} @171 trained 1 time.
args:
1: Source @045 ⏎ `AbstractArray{Continuous,2}`
2: Source @500 ⏎ `AbstractArray{OrderedFactor{2},1}` It looked like it had worked in the REPL, so I went to the directory where I have all my files and moved Project.toml to a different location to have an empty |
Describe the bug
I am unable to retrieve a saved trained machine.
I have a few machines that I have already tuned stored on my computer. I have been retrieving them using
machine("mymach_1.jlso", X, y)
to make plots and inspect well each tuning process. However, today I haven't been able to retrieve any of them, I get the following error:Click to see error
I don't understand most of what it says there, but I saw the line
[warn | JLSO]: KeyError: key MLJGLMInterface [caf8df21-4939-456d-ac9c-5fefbfb04c0c] not found
so I tried] add MLJGLMInterface
andusing MLJGLMInterface
. However, I still got a very similar error:Click to see error
*note that the abovementioned line now says
[warn | JLSO]: EOFError: read end of file
instead.I am not able to provide a reproducible code because newly saved machines seem to be correctly retrieved. I only have a problem accessing those that were tuned and saved in the past.
Additional context
After I tuned my last machine (the last one of those I am not able to retrieve), I wanted to add the package
StatsPlots
to make a violin plot. However, I addedStatPlots
instead by mistake, which downgraded several packages in my environment. I rapidly did] rm StatPlots
,] add StatsPlots
and] update
, which caused several changes in myProject.toml
file. At that point I wasn't having any problems and I continued working on my project. It was only the next day that I realised that I was unable to retrieve any of the machines I had saved up to that point, although newly trained and saved machines seemed to be okay to recover. I also added thePlotlyJS
package to my environment during my last session before this problem appeared. I am unsure of the importance of all this, but everything else I did that day was in the line of what I typically would do in a normal day.Versions
VSCode: v1.53.2
OS: Windows 10
Julia: v1.4.2
output of
] status
The text was updated successfully, but these errors were encountered: