我使用下面的代码来创建一个三重丢失的暹罗网络,我在本地使用python 3.6和蟒蛇。
def triplet_loss_wrapper(margin=1.0, l2_norm=True):
def triplet_loss(y_true, y_pred):
import tensorflow as tf
return tf.subtract(y_pred[:,:,0], y_pred[:,:,1])
return triplet_loss
from keras.layers import Input, Concatenate, concatenate
from keras import Model
from keras.layers import Concatenate, Lambda
input_layer = Input(shape=(784,))
a = Dense(100, activation="relu")(input_layer)
o = Dense(40, activation="relu")(a)
layer1 = Lambda(lambda x: K.expand_dims(x, axis=-1))(o)
layer2 = Lambda(lambda x: K.expand_dims(x, axis=-1))(o)
concat_layer = concatenate([layer1, layer1], axis=2)
model = Model(input_layer, concat_layer)
model.compile(optimizer=SGD(), loss=triplet_loss_wrapper())
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_test = x_test.reshape(x_test.shape[0], 784)
model.fit(x_test, [1] * len(x_test), batch_size =1)
在google colab上运行时,它运行并训练
但是,当使用蟒蛇在本地运行时,它会失败,并出现以下错误
(np_val.shape,subfeed_t.name,str(subfeed_t.get_shape()))
值错误:无法为张量提供形状(32,1)的值
“concatenate_1_target:0”,其形状为“(?????
我的水蟒里有以下包,我刚刚运行了全部更新
_许可证1.1 py36_1 alabaster 0.7.10 py36_0 anaconda自定义py36_0 anaconda客户端1.6.3 py36_0 anaconda navigator 1.6.4 py36_0
水蟒项目0.6.0 py36_0 asn1crypto 0.22.0 py36_0 astroid 1.5.3
py36_0 astropy 2.0.1 np113py36_0 babel 2.5.0 py36_0 backports 1.0
py36_0 backports.weakref 1.0rc1 py36_0 beautifulsoup4 4.6.0 py36_0
BitArray 0.8.1 Py36_0 BkCharts 0.2 Py36_0 Blas 1.0 Mkl Blaze 0.10.1
py36_0漂白剂1.5.0 py36_0 bokeh 0.12.7 py36_0 boto 2.48.0 py36_0
瓶颈1.2.1 NP113PY36_0开罗1.14.8 0证书2016.2.28 PY36_0
cffi 1.10.0 py36_0 chardet 3.0.4 py36_0单击6.7 py36_0 cloudpickle
0.4.0 py36_0 clyent 1.2.2 py36_0 colorma 0.3.9 py36_0 contextlib2 0.5.5 py36_0密码学1.8.1 py36_0 cudatoolkit 8.0 3 cudnn 6.0.21 cuda8.0_0 curl 7.52.1 0 cycler 0.10.0 py36_0 cython 0.26 py36_0
cytoolz 0.8.2 py36_0 dask 0.15.2 py36_0 datashape 0.5.4 py36_0 dbus
1.10.20 0装饰器4.1.2 py36_0分布式1.18.1 py36_0 docutils 0.14 py36_0 entrypoints 0.2.3 py36_0 et_xmlfile 1.0.1 py36_0 expat 2.1.0 0 fastcache 1.0.2 py36_1 flask 0.12.2 py36_0 flask cors 3.0.3 py36_0 fontconfig 2.12.1 3 freetype 2.5.5 2 get_terminal_size 1.0.0
py36_0 gevent 1.2.2 py36_0 glib 2.50.2 1 greenlet 0.4.12 py36_0
GST插件基础1.8.0 0 gstreamer 1.8.0 0 0 h5py 2.7.0 NP113py36_0
harfbuzz 0.9.39 2 hdf5 1.8.17 2 heapdict 1.0.0 py36_1 html5lib
0.9999999 Py36_0 ICU 54.1 0 IDNA 2.6 Py36_0 ImageSize 0.7.1 Py36_0 Ipyernel 4.6.1 Py36_0 Ipython 6.1.0 Py36_0 Ipython_Genutils 0.2.0
py36_0 ipywidgets 6.0.0 py36_0 isort 4.2.15 py36_0 its dangerous 0.24
py36_0 jbig 2.1 0 jdcal 1.3 py36_0绝地0.10.2 py36_2 jinja2 2.9.6
py36_0 jpeg 9b 0 jsonschema 2.6.0 py36_0 jupyter 1.0.0 py36_3
Jupyter_客户端5.1.0 py36_0 jupyter_控制台5.2.0 py36_0 jupyter_核心
4.3.0 py36_0 keras 2.0.5 py36_0 lazy object proxy 1.3.1 py36_0 libffi 3.2.1 1 libgcc 5.2.0 0 libgfortran 3.0.0 1 libgpuaray 0.6.9 0 libiconv 1.14 0 libpng 1.6.30 1 libprotobuf 3.4.0 0 libnadium 1.0.10 0
libtiff 4.0.6 3 libtool 2.4.2 0 libxcb 1.12 1 libxml2 2.9.4 0 libxslt
1.1.29 0 llvmlite 0.20.0 py36_0 locket 0.2.0 py36_1 lxml 3.8.0 py36_0 mako 1.0.6 py36_0 markdown 2.6.9 py36_0 markupsafe 1.0 py36_0
Matplotlib 2.0.2 NP113PY36_0 Mistune 0.7.4 PY36_0 Mkl 2017.0.3 0
mkl服务1.1.2 py36_3 mpmath 0.19 py36_1 msgpack python 0.4.8
py36_0 multipledispatch 0.4.9 py36_0 navigator更新程序0.1.0 py36_0
nbconvert 5.2.1 py36_0 nbformat 4.4.0 py36_0 nccl 1.3.4 cuda8.0_1
网络x 1.11 py36_0 nltk 3.2.4 py36_0 nose 1.3.7 py36_1笔记本
5.0.0 py36_0 numba 0.35.0 np113py36_0 numexpr 2.6.2 np113py36_0 numpy 1.13.1 py36_0 numpydoc 0.7.0 py36_0 odo 0.5.1 py36_0 olefile 0.44 py36_0 openpyxl 2.4.8 py36_0 openssl 1.0.2l 0包装16.8 py36_0
熊猫0.20.3 py36_0 pandocfilters 1.4.2 py36_0 pango 1.40.3 1 partd
0.3.8 py36_0 path.py 10.3.1 py36_0 pathlib2 2.3.0 py36_0 patsy 0.4.1 py36_0 pcre 8.39 1 pep8 1.7.0 py36_0 pexpect 4.2.1 py36_0 pickleshare
0.7.4 0.7.4 py36-0枕头4.2.1 py36-0 PiP 9.0.1 py36-1 Pixman 0.34.0 0 0 pl3.10 py36-0提示U工具箱1.0.15 py36-0 Protobuf 3.4.0 py36-0 pstil 5.2.2 py36-0 pt进程0.5.2 py36-0 py36-0 py36-0 py36-0 py36-0 py36-0 py36-0 py代码样式2.3.3.1 py36-0 pycosa0.6.2 py36-0.6.2 py36-0 py36-0 pycpparser0 0 0 0 0 0 pycppar撒器2.18 py36-2.18 py36-0 py36-0 py36-0 pycrypto 2.6.1 py36_6 pycurl 7.43.0 py36_2 pyflakes 1.6.0 py36_0 pygments 2.2.0
py36_0 pygpu 0.6.9 py36_0 pylint 1.7.2 py36_0 pyodbc 4.0.17 py36_0
pyopenssl 17.0.0 py36_0 pyparsing 2.2.0 py36_0 pyqt 5.6.0 py36_2
pytables 3.4.2 NP113py36_0 pytest 3.2.1 py36_0 python 3.6.2 0
python dateutil 2.6.1 py36_0 pytorch 0.1.12 py36cuda8.0自定义6.0_1 pytz
2017.2 py36_0 pywafts 0.5.2 np113py36_0 pyyaml 3.12 py36_0 pyzmq 16.0.2 py36_0 qt 5.6.2 4 qtawe 0.4.4 py36_0 qtcole 4.3.1 py36_0 qtpy 1.3.1 py36_0 readline 6.2 2请求2.14.2 py36_0 rope 0.9.4
PY36_1 Ruamel_Yaml 0.11.14 PY36_1 Scikit图像0.13.0 NP113PY36_0
SciKit学习0.19.0 np113py36_0 scipy 0.19.1 np113py36_0 Seaborn 0.8
py36_0安装工具36.4.0 py36_1 simplegeneric 0.8.1 py36_1
单调度3.4.0.3 py36_0 sip 4.18 py36_0 six 1.10.0 py36_0
Snowballstemmer 1.2.1 PY36_0分类收集0.5.3 PY36_0
分拣集装箱1.5.7 PY36_0 Sphinx 1.6.3 PY36_0 SphinxContrib 1.0
py36_0 sphinxcontrib网站支持1.0.1 py36_0 spyder 3.2.3 py36_0
sqlAlchemy 1.1.13 py36_0 sqlite 3.13.0 0 0 statsmodels 0.8.0 np113py36_0
症状1.1.1 py36_0 tblib 1.3.2 py36_0 tensorflow 1.3.0 0
张力流基础1.3.0 py36h5293eaa_1张力流张力板0.1.5
py36_0 Terminado 0.6 py36_0 testpath 0.3.1 py36_0 theano 0.9.0 py36_0
tk 8.5.18 0 toolz 0.8.2 py36_0 torchvision 0.1.8 py36_0 tornado 4.5.2
py36_0 traitlets 4.3.2 py36_0 unicodecsv 0.14.1 py36_0 unixodc 2.3.4
0 wc宽度0.1.7 py36_0 werkzeug 0.12.2 py36_0车轮0.29.0 py36_0
widgetsnbextension 3.0.2 py36_0 wrapt 1.10.11 py36_0 xlrd 1.1.0 py36_0
XLSxWriter 0.9.8 py36_0 xlwt 1.3.0 py36_0 xz 5.2.3 0 yaml 0.1.6 0
zeromq 4.1.5 0 zict 0.1.2 py36_0 zlib 1.2.11 0
你知道为什么它在Colab上运行但在本地崩溃吗?