如何解决张量必须来自同一张图
我正在尝试使用此代码来可视化CNN的内核。在此之前,我已经训练了CNN(称为complete_model)。我还检查了论坛上提出的其他类似问题,但没有任何帮助。
def deprocess_image(x):
x -= x.mean()
x /= (x.std() + 1e-5)
x *= 0.1
x += 0.5
x = np.clip(x,1)
x *= 255
x = np.clip(x,255).astype('uint8')
return x
def generate_pattern(layer_name,filter_index,size=150):
layer_output = complete_model.get_layer(layer_name).output
loss = K.mean(layer_output[:,:,filter_index])
grads = K.gradients(loss,complete_model.input)[0]
grads /= (K.sqrt(K.mean(K.square(grads))) + 1e-5)
iterate = K.function([complete_model.input],[loss,grads])
input_img_data = np.random.random((1,size,3)) * 20 + 128.
step = 1.
for i in range(80):
loss_value,grads_value = iterate([input_img_data])
input_img_data += grads_value * step
img = input_img_data[0]
return deprocess_image(img)
fig = plt.figure(figsize=(15,12))
for img in range(30):
ax = fig.add_subplot(5,6,img+1)
ax = plt.imshow(generate_pattern('conv2d_1',img))
plt.xticks([])
plt.yticks([])
fig.subplots_adjust(wspace=0.05,hspace=0.05)
我不断收到以下错误:
ValueError:Tensor(“ Const_13:0”,shape =(3,),dtype = int32)必须与Tensor(“ strided_slice_22:0”,shape =(None,147,147),dtype来自同一张图= float32)(图形为
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。