Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 函数调用堆栈:使用LSTM进行训练时出现训练_函数错误_Python_Pandas_Tensorflow_Keras_Recurrent Neural Network - Fatal编程技术网

Python 函数调用堆栈:使用LSTM进行训练时出现训练_函数错误

Python 函数调用堆栈:使用LSTM进行训练时出现训练_函数错误,python,pandas,tensorflow,keras,recurrent-neural-network,Python,Pandas,Tensorflow,Keras,Recurrent Neural Network,每当我尝试使用LSTM 以下是我的数据的示例: Unnamed: 0 STDEV1 AVG1 ... AVG2 MDN2 EMOSI 0 0 0.289292 0.207629 ... 8.807916 11.992098 1 1 1 0.250791 0.413052 ... 69.249512 101.720074 1 2 2

每当我尝试使用
LSTM

以下是我的数据的示例:

Unnamed: 0       STDEV1      AVG1  ...       AVG2        MDN2     EMOSI
0            0  0.289292  0.207629  ...   8.807916   11.992098      1
1            1  0.250791  0.413052  ...  69.249512  101.720074      1
2            2  0.253807  0.338387  ...  31.580711   19.017516      1
3            3  0.263384  0.407921  ...  32.818473   26.808509      1
4            4  0.226528  0.455874  ...  73.241437   75.999870      1
5            5  0.277033  0.221476  ...   8.942901    8.350342      1
6            6  0.292980  0.410113  ...  28.749170   26.776201      1
7            7  0.285785  0.420846  ...  11.603344   11.883280      1
.....................................................................
35          35  0.239678  0.118683  ...   0.711407    0.659205      4
36          36  0.264014  0.573877  ...   1.295760    1.617357      4
37          37  0.188601  0.521860  ...  86.919618   83.608340      4
38          38  0.313663  0.278360  ...   0.966535    0.940959      4
39          39  0.309995  0.354291  ...   0.381528    0.291138      4
这是数据预处理的方式:

X=np.array(df.drop('EMOSI',轴=1))
y=np.array(pd.get_dummies(df['EMOSI']))
长度=40
列车数量=29
index=np.random.randint(0,长度,大小=长度)
列车X=X[索引[0:num\u列车]]
列车Y=Y[索引[0:num\u列车]]
测试X=X[索引[num\u train:]
测试Y=Y[索引[num\u train:]
这是我的模型

def create_model():
模型=keras.models.Sequential([
keras.layers.Embeding(输入尺寸=5,输出尺寸=7),
第LSTM(7)层路缘石,
keras.层.致密(4,活化='softmax')
])
优化器=keras.optimizers.Adam(lr=0.01)
model.compile(
损失class='classifical_crossentropy',
优化器=优化器,
指标=['acc']
)
model.summary()
回归模型
当我训练数据时:

history=model.fit(
列车(X),
训练,
纪元=200,
验证数据=(测试X,测试Y),
回调=[提前停止],
详细=0
)
>>>错误可能源于输入操作。
连接到节点顺序/嵌入/嵌入\u查找的输入源操作:
顺序/embedding/embedding\u lookup/1883(定义于C:\Users\User\AppData\Local\Programs\Python\Python36\lib\contextlib.py:81)
函数调用堆栈:
列车功能
以下是我的模型的摘要:

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
embedding (Embedding)        (None, None, 7)           35        
_________________________________________________________________
lstm (LSTM)                  (None, 7)                 420       
_________________________________________________________________
dense (Dense)                (None, 4)                 32        
=================================================================
Total params: 487
Trainable params: 487
Non-trainable params: 0
因此,我的猜测是,我的数据只有
2维
,而模型的第一层需要
3维
。但这可能是错误的,因为
3rd-dimension
可以从
LSTM
层输出输入。 我不知道如何解决这个问题

*编辑,这里是错误的完整部分

Traceback (most recent call last):
  File "E:\Kuliah\Tugas Akhir\Source Code\test_git\SkripsiEmosiRNN\main.py", line 91, in <module>
    callbacks=[early_stopping],
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1100, in fit
    tmp_logs = self.train_function(iterator)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\eager\def_function.py", line 828, in __call__
    result = self._call(*args, **kwds)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\eager\def_function.py", line 888, in _call
    return self._stateless_fn(*args, **kwds)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\eager\function.py", line 2943, in __call__
    filtered_flat_args, captured_inputs=graph_function.captured_inputs)  # pylint: disable=protected-access
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\eager\function.py", line 1919, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager))
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\eager\function.py", line 560, in call
    ctx=ctx)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\eager\execute.py", line 60, in quick_execute
    inputs, attrs, num_outputs)
tensorflow.python.framework.errors_impl.InvalidArgumentError:  indices[0,0] = 8 is not in [0, 5)
     [[node sequential/embedding/embedding_lookup (defined at E:\Kuliah\Tugas Akhir\Source Code\test_git\SkripsiEmosiRNN\main.py:91) ]] [Op:__inference_train_function_3063]

Errors may have originated from an input operation.
Input Source operations connected to node sequential/embedding/embedding_lookup:
 sequential/embedding/embedding_lookup/1885 (defined at C:\Users\User\AppData\Local\Programs\Python\Python36\lib\contextlib.py:81)

Function call stack:
train_function
回溯(最近一次呼叫最后一次):
文件“E:\Kuliah\Tugas Akhir\Source Code\test\u git\SkripsiEmosiRNN\main.py”,第91行,在
回调=[提前停止],
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\tensorflow\Python\keras\engine\training.py”,第1100行
tmp_logs=self.train_函数(迭代器)
文件“C:\Users\User\AppData\Local\Programs\Python\36\lib\site packages\tensorflow\Python\eager\def\u function.py”,第828行,在\uu调用中__
结果=自身调用(*args,**kwds)
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\tensorflow\Python\eager\def\u function.py”,第888行,在调用中
返回self.\u无状态\u fn(*args,**kwds)
文件“C:\Users\User\AppData\Local\Programs\Python\36\lib\site packages\tensorflow\Python\eager\function.py”,第2943行,在调用中__
过滤的参数,捕获的输入=图形函数。捕获的输入)#pylint:disable=受保护的访问
文件“C:\Users\User\AppData\Local\Programs\Python\36\lib\site packages\tensorflow\Python\eager\function.py”,第1919行,位于调用平面中
ctx,args,取消管理器=取消管理器)
调用中第560行的文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\tensorflow\Python\eager\function.py”
ctx=ctx)
文件“C:\Users\User\AppData\Local\Programs\Python36\lib\site packages\tensorflow\Python\eager\execute.py”,第60行,快速执行
输入、属性、数量(输出)
tensorflow.python.framework.errors\u impl.InvalidArgumentError:索引[0,0]=8不在[0,5]中
[[node sequential/embedding/embedding_lookup(定义于E:\Kuliah\Tugas-Akhir\Source Code\test_-git\SkripsiEmosiRNN\main.py:91)][Op:[推理训练函数]
错误可能源于输入操作。
连接到节点顺序/嵌入/嵌入\u查找的输入源操作:
顺序/embedding/embedding\u lookup/1885(定义于C:\Users\User\AppData\Local\Programs\Python\Python36\lib\contextlib.py:81)
函数调用堆栈:
列车功能

不确定如何解决此问题,但Keras是否更新为最新版本?您只包含了部分错误,请包含完整的回溯。@AdityaK是的,它是的最新版本Keras@Dr.Snoopy更新了帖子中的完整回溯,谢谢你知道嵌入层是如何工作的吗?因为你没有正确使用它,词汇表泽似乎不正确。