def __init__(self, input_dim=(3, 32, 32), num_filters=32, filter_size=7, hidden_dim=100, num_classes=10, weight_scale=1e-3, reg=0.0, dtype=np.float32): self.params = {} self.reg = reg self.dtype = dtype # Initialize weights and biases C, H, W = input_dim self.params['W1'] = weight_scale * np.random.randn(num_filters, C, filter_size, filter_size) self.params['b1'] = np.zeros(num_filters) self.params['W2'] = weight_scale * np.random.randn(num_filters * H * W // 4, hidden_dim) self.params['b2'] = np.zeros(hidden_dim) self.params['W3'] = weight_scale * np.random.randn(hidden_dim, num_classes) self.params['b3'] = np.zeros(num_classes) for k, v in self.params.iteritems(): self.params[k] = v.astype(dtype)报错 'dict' object has no attribute 'iteritems'
时间: 2024-03-20 21:42:25 浏览: 56
这个错误是因为在Python3中,`dict`对象没有`iteritems()`方法,而是使用`items()`方法代替。因此,在这段代码中,将`iteritems()`改为`items()`即可:
```
for k, v in self.params.items():
self.params[k] = v.astype(dtype)
```
这样就可以避免报错了。
阅读全文