Flux.jl/latest/apis/storage.html
2017-05-04 16:23:01 +00:00

208 lines
6.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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">
Simple MNIST
</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>
<a class="edit-page" href="https://github.com/MikeInnes/Flux.jl/tree/7a85eff370b7c68d587b49699fa3f71e44993397/docs/src/apis/storage.md">
<span class="fa">
</span>
Edit on GitHub
</a>
</nav>
<hr/>
</header>
<h1>
<a class="nav-anchor" id="Loading-and-Saving-Models-1" href="#Loading-and-Saving-Models-1">
Loading and Saving Models
</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">
Simple MNIST
</span>
</a>
</footer>
</article>
</body>
</html>