# BSON confusing behaviour

**URL:** https://discourse.julialang.org/t/bson-confusing-behaviour/33700
**Category:** General Usage
**Tags:** question
**Created:** [January 23, 2020, 1:07pm UTC](https://discourse.julialang.org/t/bson-confusing-behaviour/33700 "2020-01-23T13:07:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)
#### Post date: [January 23, 2020, 1:07pm UTC](https://discourse.julialang.org/t/bson-confusing-behaviour/33700/1 "2020-01-23T13:07:41Z")

</div>

Apologies for so many questions in so short a time, but I have decided to do a “push”, so I am tackling the issues in sequence (and there are alot of them).

Regarding using BSON to load: Here is an example of trying to load a model:

> using BSON  
> BSON.load(“/home/davide/france/julia\_scripts/nntest.jls”)

Dict{Symbol,Any} with 1 entry:  
:dict1 =\> Dict(“mw”=\>Chain(Dense(68, 5), BatchNorm(5, \<\lambda\> = relu), Dense(5, 5),…

> mw=dict1[“mw”]  
> UndefVarError: dict1 not defined

* * *

Following instructions for BSON, I had saved the dictionary dict1, and (apparently) loaded it successfully, but when I tried to access it, it is not there.

Can anyone help please?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [January 23, 2020, 1:11pm UTC](https://discourse.julialang.org/t/bson-confusing-behaviour/33700/2 "2020-01-23T13:11:01Z")

</div>

It is unlikely that `BSON.load` defines a local variable. You would need to do something like:\*

```julia
using BSON
data = BSON.load("/home/davide/france/julia_scripts/nntest.jls")
dict1 = data[:dict1]
mw = dict1["mw"]

```

---

<div class="post-metadata">

### Author: ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)
#### Post date: [January 23, 2020, 1:29pm UTC](https://discourse.julialang.org/t/bson-confusing-behaviour/33700/3 "2020-01-23T13:29:58Z")

</div>

Thanks Kristoffer.

Actually, I had saved it using BSON.@save and had tried BSON.@load  
and that had worked in the ‘intuitive’ way above (with dict1 just appearing) at the time, but it has stopped working that way.

Yes - your way works - thanks! I had tried data[“dict1”] and don’t know why the colon appeared or why it is necessary and why quotes aren’t necessary, but I guess I’ll just have to remember it. Thanks.

\*\*\*\* Update \*\*\*\* most issues I have had with this seem to relate to differing types of objects saved by different versions of Flux (models from v0.9.0 and v0.10.1 are not the same types of objects). Also a bit of confusion going back and forth between BSON.save/load and BSON.@save/@load
