<p dir="auto">I am using sklearn for my project i have trained model on 64 bit linux machine,now i want to load that model (.pickle format) on raspberry pi which is 32 bit os and hw configuration,i have following issue while unpickling model file.<br>
Please help me if any solution on this.</p>
<p dir="auto">knn_clf =joblib.load(f)<br>
File "/usr/local/lib/python3.5/dist-packages/sklearn/externals/joblib/numpy_pickle.py", line 568, in load<br>
obj = _unpickle(fobj)<br>
File "/usr/local/lib/python3.5/dist-packages/sklearn/externals/joblib/numpy_pickle.py", line 508, in _unpickle<br>
obj = unpickler.load()<br>
File "/usr/lib/python3.5/pickle.py", line 1043, in load<br>
dispatch<a href="self">key[0]</a><br>
File "/usr/local/lib/python3.5/dist-packages/sklearn/externals/joblib/numpy_pickle.py", line 328, in load_build<br>
Unpickler.load_build(self)<br>
File "/usr/lib/python3.5/pickle.py", line 1518, in load_build<br>
setstate(state)<br>
File "sklearn/neighbors/binary_tree.pxi", line 1128, in sklearn.neighbors.ball_tree.BinaryTree.<em>setstate</em><br>
File "sklearn/neighbors/binary_tree.pxi", line 228, in sklearn.neighbors.ball_tree.get_memview_ITYPE_1D<br>
ValueError: Buffer dtype mismatch, expected 'ITYPE_t' but got 'long long'</p>
<h4 dir="auto">Description</h4>
<p dir="auto"><code class="notranslate">ValueError: Did not recognise loaded array layout</code> thrown when loading model pickled in 32 bit Linux and loaded on 32 bit Windows. The reverse is also true. Models can be pickled/loaded on their respective OS so it seems to be a cross-platform issue.</p>
<p dir="auto">I've tried both joblib and pickle and ensured that library versions are the same on Windows and Linux. Libraries were obtained using miniconda from the anaconda channel using libraries uploaded by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/kalefranz/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/kalefranz">@kalefranz</a> (<a href="https://anaconda.org/anaconda/scikit-learn" rel="nofollow">https://anaconda.org/anaconda/scikit-learn</a>)</p>
<p dir="auto">Seems similar to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="147693489" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/6650" data-hovercard-type="issue" data-hovercard-url="/scikit-learn/scikit-learn/issues/6650/hovercard" href="https://github.com/scikit-learn/scikit-learn/issues/6650">#6650</a>. 64 bit models are able to load. However, 32 bit is a requirement for my use case.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<p dir="auto">Minimum code to reproduce</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="create_model.py

from sklearn.externals import joblib
import numpy as np
from sklearn.ensemble import RandomForestClassifier
import pickle

X = np.random.randn(1500,8)
l = np.random.randint(6, size = 1500)
clf_forest = RandomForestClassifier(n_estimators = 10)
clf_forest.fit(X,l)
joblib.dump(clf_forest,'joblib_clf_forest_win.pkl')

with open('pickle_clf_forest_win.pkl', 'wb') as f:
  pickle.dump(clf_forest, f)"><pre class="notranslate"><code class="notranslate">create_model.py

from sklearn.externals import joblib
import numpy as np
from sklearn.ensemble import RandomForestClassifier
import pickle

X = np.random.randn(1500,8)
l = np.random.randint(6, size = 1500)
clf_forest = RandomForestClassifier(n_estimators = 10)
clf_forest.fit(X,l)
joblib.dump(clf_forest,'joblib_clf_forest_win.pkl')

with open('pickle_clf_forest_win.pkl', 'wb') as f:
  pickle.dump(clf_forest, f)
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pickle_load.py

import pickle

with open('pickle_clf_forest.pkl', 'rb') as f: 
  pickle.load(f)
"><pre class="notranslate"><code class="notranslate">pickle_load.py

import pickle

with open('pickle_clf_forest.pkl', 'rb') as f: 
  pickle.load(f)

</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="joblib_load.py

from sklearn.externals import joblib

a = joblib.load('joblib_clf_forest.pkl')
"><pre class="notranslate"><code class="notranslate">joblib_load.py

from sklearn.externals import joblib

a = joblib.load('joblib_clf_forest.pkl')

</code></pre></div>
<h4 dir="auto">Expected Results</h4>
<p dir="auto">No error is thrown.</p>
<h4 dir="auto">Actual Results</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(..\exe\virtualenvs\32-sklearn0191)$ python joblib_load.py
Windows-7-6.1.7601-SP1
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 14:16:49) [MSC v
.1900 32 bit (Intel)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1
Traceback (most recent call last):
  File &quot;joblib_load.py&quot;, line 9, in &lt;module&gt;
    a = joblib.load('joblib_clf_forest.pkl')
  File &quot;virtualenvs\32-sklearn0191\lib\site-packages\sklear
n\externals\joblib\numpy_pickle.py&quot;, line 578, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File &quot;virtualenvs\32-sklearn0191\lib\site-packages\sklear
n\externals\joblib\numpy_pickle.py&quot;, line 508, in _unpickle
    obj = unpickler.load()
  File &quot;virtualenvs\32-sklearn0191\lib\pickle.py&quot;, line 105
0, in load
    dispatch[key[0]](self)
  File &quot;virtualenvs\32-sklearn0191\lib\site-packages\sklear
n\externals\joblib\numpy_pickle.py&quot;, line 328, in load_build
    Unpickler.load_build(self)
  File &quot;virtualenvs\32-sklearn0191\lib\pickle.py&quot;, line 150
8, in load_build
    setstate(state)
  File &quot;sklearn\tree\_tree.pyx&quot;, line 667, in sklearn.tree._tree.Tree.__setstate
__
ValueError: Did not recognise loaded array layout"><pre class="notranslate"><code class="notranslate">(..\exe\virtualenvs\32-sklearn0191)$ python joblib_load.py
Windows-7-6.1.7601-SP1
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 14:16:49) [MSC v
.1900 32 bit (Intel)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1
Traceback (most recent call last):
  File "joblib_load.py", line 9, in &lt;module&gt;
    a = joblib.load('joblib_clf_forest.pkl')
  File "virtualenvs\32-sklearn0191\lib\site-packages\sklear
n\externals\joblib\numpy_pickle.py", line 578, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File "virtualenvs\32-sklearn0191\lib\site-packages\sklear
n\externals\joblib\numpy_pickle.py", line 508, in _unpickle
    obj = unpickler.load()
  File "virtualenvs\32-sklearn0191\lib\pickle.py", line 105
0, in load
    dispatch[key[0]](self)
  File "virtualenvs\32-sklearn0191\lib\site-packages\sklear
n\externals\joblib\numpy_pickle.py", line 328, in load_build
    Unpickler.load_build(self)
  File "virtualenvs\32-sklearn0191\lib\pickle.py", line 150
8, in load_build
    setstate(state)
  File "sklearn\tree\_tree.pyx", line 667, in sklearn.tree._tree.Tree.__setstate
__
ValueError: Did not recognise loaded array layout
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(..\exe\virtualenvs\32-sklearn0191) $ python pickle_load.py
Windows-7-6.1.7601-SP1
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 14:16:49) [MSC v
.1900 32 bit (Intel)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1
Traceback (most recent call last):
  File &quot;pickle_load.py&quot;, line 10, in &lt;module&gt;
    pickle.load(f)
  File &quot;sklearn\tree\_tree.pyx&quot;, line 667, in sklearn.tree._tree.Tree.__setstate
__
ValueError: Did not recognise loaded array layout"><pre class="notranslate"><code class="notranslate">(..\exe\virtualenvs\32-sklearn0191) $ python pickle_load.py
Windows-7-6.1.7601-SP1
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 14:16:49) [MSC v
.1900 32 bit (Intel)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1
Traceback (most recent call last):
  File "pickle_load.py", line 10, in &lt;module&gt;
    pickle.load(f)
  File "sklearn\tree\_tree.pyx", line 667, in sklearn.tree._tree.Tree.__setstate
__
ValueError: Did not recognise loaded array layout
</code></pre></div>
<h4 dir="auto">Versions</h4>
<p dir="auto">Windows 32 conda environment:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Windows-7-6.1.7601-SP1
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 14:16:49) [MSC v
.1900 32 bit (Intel)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1"><pre class="notranslate"><code class="notranslate">Windows-7-6.1.7601-SP1
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 14:16:49) [MSC v
.1900 32 bit (Intel)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# packages in environment at virtualenvs\32-sklearn0191:
#
altgraph                  0.14                      &lt;pip&gt;
appdirs                   1.4.0                     &lt;pip&gt;
certifi                   2016.2.28                py36_0
certifi                   2017.11.5                 &lt;pip&gt;
chardet                   3.0.4                     &lt;pip&gt;
future                    0.16.0                    &lt;pip&gt;
icc_rt                    2017.0.4             h97af966_0    anaconda
idna                      2.6                       &lt;pip&gt;
intel-openmp              2018.0.0             hda8db3e_7    anaconda
macholib                  1.8                       &lt;pip&gt;
mkl                       2018.0.0             hd024497_4    anaconda
mock                      2.0.0                     &lt;pip&gt;
numpy                     1.13.3           py36h38e73f1_0    anaconda
packaging                 16.8                      &lt;pip&gt;
pandas                    0.20.3           py36h93e7217_2    anaconda
pandas                    0.20.3                    &lt;pip&gt;
pbr                       3.1.1                     &lt;pip&gt;
pefile                    2017.9.3                  &lt;pip&gt;
pip                       9.0.1                    py36_1
psycopg2                  2.7.3.2                   &lt;pip&gt;
PyInstaller               3.3                       &lt;pip&gt;
pyparsing                 2.2.0                     &lt;pip&gt;
pypiwin32                 220                       &lt;pip&gt;
python                    3.6.1                         2
python-dateutil           2.6.1            py36h507c767_1    anaconda
python-dateutil           2.6.1                     &lt;pip&gt;
python-magic              0.4.5                     &lt;pip&gt;
pytz                      2017.3                    &lt;pip&gt;
pytz                      2017.2           py36h6ca8096_1    anaconda
PyYAML                    3.12                      &lt;pip&gt;
requests                  2.18.4                    &lt;pip&gt;
scikit-learn              0.19.1           py36hb0057d7_0    anaconda
scipy                     0.19.1           py36hfc7e94f_3    anaconda
setuptools                36.4.0                   py36_1
six                       1.11.0           py36h7f2c006_1    anaconda
six                       1.11.0                    &lt;pip&gt;
SQLAlchemy                1.1.15                    &lt;pip&gt;
urllib3                   1.22                      &lt;pip&gt;
vc                        14                            0
vs2015_runtime            14.0.25420                    0
wheel                     0.29.0                   py36_0
wincertstore              0.2                      py36_0
XlsxWriter                0.9.6                     &lt;pip&gt;"><pre class="notranslate"><code class="notranslate"># packages in environment at virtualenvs\32-sklearn0191:
#
altgraph                  0.14                      &lt;pip&gt;
appdirs                   1.4.0                     &lt;pip&gt;
certifi                   2016.2.28                py36_0
certifi                   2017.11.5                 &lt;pip&gt;
chardet                   3.0.4                     &lt;pip&gt;
future                    0.16.0                    &lt;pip&gt;
icc_rt                    2017.0.4             h97af966_0    anaconda
idna                      2.6                       &lt;pip&gt;
intel-openmp              2018.0.0             hda8db3e_7    anaconda
macholib                  1.8                       &lt;pip&gt;
mkl                       2018.0.0             hd024497_4    anaconda
mock                      2.0.0                     &lt;pip&gt;
numpy                     1.13.3           py36h38e73f1_0    anaconda
packaging                 16.8                      &lt;pip&gt;
pandas                    0.20.3           py36h93e7217_2    anaconda
pandas                    0.20.3                    &lt;pip&gt;
pbr                       3.1.1                     &lt;pip&gt;
pefile                    2017.9.3                  &lt;pip&gt;
pip                       9.0.1                    py36_1
psycopg2                  2.7.3.2                   &lt;pip&gt;
PyInstaller               3.3                       &lt;pip&gt;
pyparsing                 2.2.0                     &lt;pip&gt;
pypiwin32                 220                       &lt;pip&gt;
python                    3.6.1                         2
python-dateutil           2.6.1            py36h507c767_1    anaconda
python-dateutil           2.6.1                     &lt;pip&gt;
python-magic              0.4.5                     &lt;pip&gt;
pytz                      2017.3                    &lt;pip&gt;
pytz                      2017.2           py36h6ca8096_1    anaconda
PyYAML                    3.12                      &lt;pip&gt;
requests                  2.18.4                    &lt;pip&gt;
scikit-learn              0.19.1           py36hb0057d7_0    anaconda
scipy                     0.19.1           py36hfc7e94f_3    anaconda
setuptools                36.4.0                   py36_1
six                       1.11.0           py36h7f2c006_1    anaconda
six                       1.11.0                    &lt;pip&gt;
SQLAlchemy                1.1.15                    &lt;pip&gt;
urllib3                   1.22                      &lt;pip&gt;
vc                        14                            0
vs2015_runtime            14.0.25420                    0
wheel                     0.29.0                   py36_0
wincertstore              0.2                      py36_0
XlsxWriter                0.9.6                     &lt;pip&gt;
</code></pre></div>
<p dir="auto">Linux 32 bit environment</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Dockerfile

FROM continuumio/miniconda3

RUN apt-get update \
    &amp;&amp; apt-get install -y libc6-i386 lib32stdc++6 python3-dev gcc libmagic-dev

RUN CONDA_FORCE_32BIT=1 conda create -n 32"><pre class="notranslate"><code class="notranslate">Dockerfile

FROM continuumio/miniconda3

RUN apt-get update \
    &amp;&amp; apt-get install -y libc6-i386 lib32stdc++6 python3-dev gcc libmagic-dev

RUN CONDA_FORCE_32BIT=1 conda create -n 32
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Linux-4.9.49-moby-x86_64-with-debian-8.9
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:08:54) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1"><pre class="notranslate"><code class="notranslate">Linux-4.9.49-moby-x86_64-with-debian-8.9
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:08:54) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="boto3                     1.4.4                     &lt;pip&gt;
botocore                  1.5.95                    &lt;pip&gt;
ca-certificates           2017.08.26           h1d4fec5_0  
certifi                   2017.7.27.1      py36h3f8508d_0  
chardet                   3.0.4                     &lt;pip&gt;
docutils                  0.14                      &lt;pip&gt;
future                    0.16.0                    &lt;pip&gt;
idna                      2.6                       &lt;pip&gt;
imbalanced-learn          0.3.1                     &lt;pip&gt;
intel-openmp              2018.0.0             h76c16ec_7    anaconda
Jinja2                    2.9.6                     &lt;pip&gt;
jmespath                  0.9.3                     &lt;pip&gt;
libgcc-ng                 7.2.0                h7cc24e2_2  
libgfortran-ng            7.2.0                h9f7466a_2    anaconda
libstdcxx-ng              7.2.0                h7a57d05_2    anaconda
MarkupSafe                1.0                       &lt;pip&gt;
mkl                       2018.0.0             haa892f1_4    anaconda
numpy                     1.13.3           py36hde72de1_0    anaconda
openssl                   1.0.2m               h7e5a0c8_0  
pandas                    0.20.3           py36hd73fee5_2    anaconda
pefile                    2017.9.3                  &lt;pip&gt;
pip                       9.0.1            py36hdf7ad74_4  
psycopg2                  2.7.3                     &lt;pip&gt;
python                    3.6.1                         2  
python-dateutil           2.6.1            py36h0ec02a2_1    anaconda
python-dateutil           2.6.1                     &lt;pip&gt;
python-magic              0.4.13                    &lt;pip&gt;
pytz                      2017.2           py36hbc70297_0    anaconda
raven                     6.3.0                     &lt;pip&gt;
readline                  6.2                           2  
requests                  2.18.4                    &lt;pip&gt;
s3transfer                0.1.11                    &lt;pip&gt;
scikit-learn              0.19.1           py36h4fdfdbb_0    anaconda
scipy                     0.19.1           py36hc385b52_3    anaconda
setuptools                36.5.0           py36h9e9eae1_0  
six                       1.11.0           py36hd5049a8_1    anaconda
six                       1.11.0                    &lt;pip&gt;
sqlite                    3.13.0                        0  
tk                        8.5.18                        0  
urllib3                   1.22                      &lt;pip&gt;
vtservices                1.1.0                     &lt;pip&gt;
wheel                     0.29.0           py36h1274d80_1  
xz                        5.2.3                ha3e1f4e_2  
zlib                      1.2.11               h907e355_2  "><pre class="notranslate"><code class="notranslate">boto3                     1.4.4                     &lt;pip&gt;
botocore                  1.5.95                    &lt;pip&gt;
ca-certificates           2017.08.26           h1d4fec5_0  
certifi                   2017.7.27.1      py36h3f8508d_0  
chardet                   3.0.4                     &lt;pip&gt;
docutils                  0.14                      &lt;pip&gt;
future                    0.16.0                    &lt;pip&gt;
idna                      2.6                       &lt;pip&gt;
imbalanced-learn          0.3.1                     &lt;pip&gt;
intel-openmp              2018.0.0             h76c16ec_7    anaconda
Jinja2                    2.9.6                     &lt;pip&gt;
jmespath                  0.9.3                     &lt;pip&gt;
libgcc-ng                 7.2.0                h7cc24e2_2  
libgfortran-ng            7.2.0                h9f7466a_2    anaconda
libstdcxx-ng              7.2.0                h7a57d05_2    anaconda
MarkupSafe                1.0                       &lt;pip&gt;
mkl                       2018.0.0             haa892f1_4    anaconda
numpy                     1.13.3           py36hde72de1_0    anaconda
openssl                   1.0.2m               h7e5a0c8_0  
pandas                    0.20.3           py36hd73fee5_2    anaconda
pefile                    2017.9.3                  &lt;pip&gt;
pip                       9.0.1            py36hdf7ad74_4  
psycopg2                  2.7.3                     &lt;pip&gt;
python                    3.6.1                         2  
python-dateutil           2.6.1            py36h0ec02a2_1    anaconda
python-dateutil           2.6.1                     &lt;pip&gt;
python-magic              0.4.13                    &lt;pip&gt;
pytz                      2017.2           py36hbc70297_0    anaconda
raven                     6.3.0                     &lt;pip&gt;
readline                  6.2                           2  
requests                  2.18.4                    &lt;pip&gt;
s3transfer                0.1.11                    &lt;pip&gt;
scikit-learn              0.19.1           py36h4fdfdbb_0    anaconda
scipy                     0.19.1           py36hc385b52_3    anaconda
setuptools                36.5.0           py36h9e9eae1_0  
six                       1.11.0           py36hd5049a8_1    anaconda
six                       1.11.0                    &lt;pip&gt;
sqlite                    3.13.0                        0  
tk                        8.5.18                        0  
urllib3                   1.22                      &lt;pip&gt;
vtservices                1.1.0                     &lt;pip&gt;
wheel                     0.29.0           py36h1274d80_1  
xz                        5.2.3                ha3e1f4e_2  
zlib                      1.2.11               h907e355_2  
</code></pre></div>