gpt4 book ai didi

python - keras - TypeError : 'int' object is not iterable

转载 作者:太空狗 更新时间:2023-10-30 01:47:45 25 4
gpt4 key购买 nike

我正在尝试测试网络,但似乎遇到了一个烦人的错误,我不太确定自己是否理解。

import keras
from keras.models import Sequential
from keras.optimizers import SGD
from keras.layers.core import Dense, Activation, Lambda, Reshape,Flatten
from keras.layers import Conv1D,Conv2D,MaxPooling2D, MaxPooling1D, Reshape
from keras.utils import np_utils
from keras.models import Model
from keras.layers import Input, Dense
from keras.layers import Dropout
from keras import backend as K
from keras.callbacks import ReduceLROnPlateau
from keras.callbacks import CSVLogger
from keras.callbacks import EarlyStopping
from keras.layers.merge import Concatenate
from keras.callbacks import ModelCheckpoint
import random
import numpy as np


window_height = 8
filter_size=window_height
pooling_size = 28
stride_step = 2


def fws():


np.random.seed(100)
input = Input(5,window_height,1)
shared_conv = Conv2D(filters = 1, kernel_size = (0,window_height,1))
output = shared_conv(input)
print output.shape


fws()

错误信息:

File "experiment.py", line 34, in <module>
fws()
File "experiment.py", line 29, in fws
input = Input(5,window_height,1)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1426, in Input
input_tensor=tensor)
File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py", line 87, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1321, in __init__
batch_input_shape = tuple(batch_input_shape)
TypeError: 'int' object is not iterable

为什么会出现这个错误?

我在网络中尝试使用代码指出的共享卷积层,出于测试目的,想看看输出结果是什么?..

最佳答案

你的线路:

input = Input(5,window_height,1)

给出了这个错误。将此与 keras 的示例进行比较: https://keras.io/getting-started/functional-api-guide/

inputs = Input(shape=(784,))

Input 对象需要一个 shape 的可迭代对象,但您向它传递了一个 int。在示例中,您可以看到他们如何解决一维输入问题。

编辑:我不知道为什么这是一个流行的答案 - 如果您因为在某处遵循错误的示例代码而收到此错误,请务必使用您从中获取它的任何来源提出该错误。

关于python - keras - TypeError : 'int' object is not iterable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46541974/

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