报错信息:
Traceback (most recent call last):
File "bs.py", line 149, in <module>
tcpserver1=MYTCPServer(('192.168.0.109',54321))
File "wserver_bs.py", line 65, in __init__
self.model.load_weights(weight_filepath)
File "/home/ps/anaconda3/envs/anomaly/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 162, in load_weights
return super(Model, self).load_weights(filepath, by_name)
File "/home/ps/anaconda3/envs/anomaly/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1424, in load_weights
saving.load_weights_from_hdf5_group(f, self.layers)
File "/home/ps/anaconda3/envs/anomaly/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 749, in load_weights_from_hdf5_group
layer, weight_values, original_keras_version, original_backend)
File "/home/ps/anaconda3/envs/anomaly/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 456, in preprocess_weights_for_loading
weights[0] = np.transpose(weights[0], (3, 2, 0, 1))
File "<__array_function__ internals>", line 6, in transpose
File "/home/ps/anaconda3/envs/anomaly/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 653, in transpose
return _wrapfunc(a, 'transpose', axes)
File "/home/ps/anaconda3/envs/anomaly/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 58, in _wrapfunc
return bound(*args, **kwds)
ValueError: axes don't match array
折腾了半个晚上,上网查了各种方法都没用。
这个错是出在load_weights函数上,转移了注意力,实际上是model设置的问题!
自己坑了一手,在载入model时,采用了默认的输入尺寸:
model = cnn.CNNLikeModel()
实际上的输入张量的尺寸与默认尺寸有别,所以导致此错。
解决
1、修改函数默认值。
2、使用该函数时填入正确的值。