gpt4 book ai didi

python - 类型错误 : conv2d_v2() got an unexpected keyword argument 'filter

转载 作者:行者123 更新时间:2023-12-04 15:17:33 25 4
gpt4 key购买 nike

试图在我的设备上使用预训练的 VGG 模型运行 Coursera 类(class)中的代码。运行模型时出现此错误。这是一个关于使用 VGG 模型的预训练模型的神经风格迁移的问题。

pp = pprint.PrettyPrinter(indent=4)
model = load_vgg_model("pretrained-model/imagenet-vgg-verydeep-19.mat")
pp.pprint(model)

TypeError                                 Traceback (most recent call last)
<ipython-input-7-2a76ad487818> in <module>
1 pp = pprint.PrettyPrinter(indent=4)
----> 2 model = load_vgg_model("pretrained-model/imagenet-vgg-verydeep-19.mat")
3 pp.pprint(model)

D:\College\Machine learning\Coursera\c4\jovyan\work\week4\Neural Style Transfer\nst_utils.py in load_vgg_model(path)
127 graph = {}
128 graph['input'] = tf.Variable(np.zeros((1, CONFIG.IMAGE_HEIGHT, CONFIG.IMAGE_WIDTH, CONFIG.COLOR_CHANNELS)), dtype = 'float32')
--> 129 graph['conv1_1'] = _conv2d_relu(graph['input'], 0, 'conv1_1')
130 graph['conv1_2'] = _conv2d_relu(graph['conv1_1'], 2, 'conv1_2')
131 graph['avgpool1'] = _avgpool(graph['conv1_2'])

D:\College\Machine learning\Coursera\c4\jovyan\work\week4\Neural Style Transfer\nst_utils.py in _conv2d_relu(prev_layer, layer, layer_name)
116 model at 'layer'.
117 """
--> 118 return _relu(_conv2d(prev_layer, layer, layer_name))
119
120 def _avgpool(prev_layer):

D:\College\Machine learning\Coursera\c4\jovyan\work\week4\Neural Style Transfer\nst_utils.py in _conv2d(prev_layer, layer, layer_name)
109 W = tf.constant(W)
110 b = tf.constant(np.reshape(b, (b.size)))
--> 111 return tf.nn.conv2d(prev_layer, strides=[1, 1, 1, 1], padding='SAME') + b
112
113 def _conv2d_relu(prev_layer, layer, layer_name):

D:\Applications\Anaconda\lib\site-packages\tensorflow\python\util\dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

TypeError: conv2d_v2() got an unexpected keyword argument 'filter'

这是我加载模型的函数。

def load_vgg_model(path):

vgg = scipy.io.loadmat(path)

vgg_layers = vgg['layers']

def _conv2d(prev_layer, layer, layer_name):

W, b = _weights(layer, layer_name)
W = tf.constant(W)
b = tf.constant(np.reshape(b, (b.size)))
return tf.nn.conv2d(prev_layer, filter=W, strides=[1, 1, 1, 1], padding='SAME') + b

def _conv2d_relu(prev_layer, layer, layer_name):

return _relu(_conv2d(prev_layer, layer, layer_name))

我很困惑,因为同一模型可以在 Coursera 上运行,但不能在我的 PC 上运行。

最佳答案

关于卷积神经网络的 Coursera 类(class)使用 TensorFlow 1.2.1

我今天尝试在 Google Collab 上运行此笔记本时遇到了同样的错误。

我的解决方案是:

pip uninstall tensorflow==2.3.0

pip install tensorflow==1.2.1

关于python - 类型错误 : conv2d_v2() got an unexpected keyword argument 'filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64033469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com