Flux.jl/latest/apis/storage.html

208 lines
6.1 KiB
HTML
Raw Normal View History

2017-02-28 16:50:27 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>
Storing Models · Flux
</title>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36890222-9', 'auto');
ga('send', 'pageview');
</script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/default.min.css" rel="stylesheet" type="text/css"/>
<link href="https://fonts.googleapis.com/css?family=Lato|Ubuntu+Mono" rel="stylesheet" type="text/css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="../assets/documenter.css" rel="stylesheet" type="text/css"/>
<script>
documenterBaseURL=".."
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="../assets/documenter.js"></script>
<script src="../../versions.js"></script>
<link href="../../flux.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<nav class="toc">
<h1>
Flux
</h1>
<form class="search" action="../search.html">
<select id="version-selector" onChange="window.location.href=this.value">
<option value="#" selected="selected" disabled="disabled">
Version
</option>
</select>
<input id="search-query" name="q" type="text" placeholder="Search docs"/>
</form>
<ul>
<li>
<a class="toctext" href="../index.html">
Home
</a>
</li>
<li>
<span class="toctext">
Building Models
</span>
<ul>
<li>
<a class="toctext" href="../models/basics.html">
Model Building Basics
</a>
</li>
<li>
<a class="toctext" href="../models/templates.html">
Model Templates
</a>
</li>
<li>
<a class="toctext" href="../models/recurrent.html">
Recurrence
</a>
</li>
<li>
<a class="toctext" href="../models/debugging.html">
Debugging
</a>
</li>
</ul>
</li>
<li>
<span class="toctext">
Other APIs
</span>
<ul>
<li>
<a class="toctext" href="batching.html">
Batching
</a>
</li>
<li>
<a class="toctext" href="backends.html">
Backends
</a>
</li>
<li class="current">
<a class="toctext" href="storage.html">
Storing Models
</a>
<ul class="internal"></ul>
</li>
</ul>
</li>
<li>
<span class="toctext">
In Action
</span>
<ul>
<li>
<a class="toctext" href="../examples/logreg.html">
Logistic Regression
</a>
</li>
<li>
<a class="toctext" href="../examples/char-rnn.html">
Char RNN
</a>
</li>
</ul>
</li>
<li>
<a class="toctext" href="../contributing.html">
Contributing &amp; Help
</a>
</li>
<li>
<a class="toctext" href="../internals.html">
Internals
</a>
</li>
</ul>
</nav>
<article id="docs">
<header>
<nav>
<ul>
<li>
Other APIs
</li>
<li>
<a href="storage.html">
Storing Models
</a>
</li>
</ul>
2017-03-06 16:07:51 +00:00
<a class="edit-page" href="https://github.com/MikeInnes/Flux.jl/tree/982c105c571a1e42364fd0bcec8542cf289b3308/docs/src/apis/storage.md">
2017-02-28 16:50:27 +00:00
<span class="fa">
</span>
Edit on GitHub
</a>
</nav>
<hr/>
</header>
<h1>
2017-02-28 17:08:59 +00:00
<a class="nav-anchor" id="Loading-and-Saving-Models-1" href="#Loading-and-Saving-Models-1">
Loading and Saving Models
2017-02-28 16:50:27 +00:00
</a>
</h1>
<pre><code class="language-julia">model = Chain(Affine(10, 20), σ, Affine(20, 15), softmax)</code></pre>
<p>
Since models are just simple Julia data structures, it&#39;s very easy to save and load them using any of Julia&#39;s existing serialisation formats. For example, using Julia&#39;s built-in
<code>serialize</code>
:
</p>
<pre><code class="language-julia">open(io -&gt; serialize(io, model), &quot;model.jls&quot;, &quot;w&quot;)
open(io -&gt; deserialize(io), &quot;model.jls&quot;)</code></pre>
<p>
One issue with
<code>serialize</code>
is that it doesn&#39;t promise compatibility between major Julia versions. For longer-term storage it&#39;s good to use a package like
<a href="https://github.com/JuliaIO/JLD.jl">
JLD
</a>
.
</p>
<pre><code class="language-julia">using JLD
@save &quot;model.jld&quot; model
@load &quot;model.jld&quot;</code></pre>
<p>
However, JLD will break for some models as functions are not supported on 0.5+. You can resolve that by checking out
<a href="https://github.com/JuliaIO/JLD.jl/pull/137">
this branch
</a>
.
</p>
<p>
Right now this is the only storage format Flux supports. In future Flux will support loading and saving other model formats (on an as-needed basis).
</p>
<footer>
<hr/>
<a class="previous" href="backends.html">
<span class="direction">
Previous
</span>
<span class="title">
Backends
</span>
</a>
<a class="next" href="../examples/logreg.html">
<span class="direction">
Next
</span>
<span class="title">
Logistic Regression
</span>
</a>
</footer>
</article>
</body>
</html>