英文:
Echo State Network - AttributeError: 'NoneType' object has no attribute 'lower'
问题
I'm here to help with the translation. Please provide the specific parts you'd like me to translate.
英文:
I am trying to use the code found here in my scripts to use that Echo State Network (ESN) to solve a time series classification problem. First, I define my ESN classifier:
classifier_ESN = RC_model(lots of parameters,
dimred_method=config['dimred_method'],
lots of parameters)
But when I start the training, I get this error:
Traceback (most recent call last):
File "C:\Users\Muril\PycharmProjects\tf-gpu\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3378, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-10-457472db72b9>", line 30, in <module>
train_time = classifier_ESN.train(x_train, y_train_one_hot)
File "C:\Users\Muril\PycharmProjects\tf-gpu\Irish\ESN\modules.py", line 174, in train
if self.dimred_method.lower() == 'pca':
AttributeError: 'NoneType' object has no attribute 'lower'
From that, I have traced to error to this part of the code in the modules.py
file:
# ============ Dimensionality reduction of the reservoir states ============
if self.dimred_method.lower() == 'pca':
# matricize
N_samples = res_states.shape[0]
res_states = res_states.reshape(-1, res_states.shape[2])
# ..transform..
red_states = self._dim_red.fit_transform(res_states)
# ..and put back in tensor form
red_states = red_states.reshape(N_samples,-1,red_states.shape[1])
elif self.dimred_method.lower() == 'tenpca':
red_states = self._dim_red.fit_transform(res_states)
else: # Skip dimensionality reduction
red_states = res_states
So, dimred_method
is a parameter passed to the ESN function RC_model
. This parameter comes from a dictionary called config
, which has this pair of key/value:
config['dimred_method'] = None # options: {None (no dimensionality reduction), 'pca', 'tenpca'}
As we can see, None
is an option to dimred_method
which should fall in the else
case of the code provided in the modules.py
, but it throws that error. I get it is because of the lower()
attribute in the case of using strings like 'pca'
or 'tenpca'
, but I am not sure how to fix it. Any ideas?
答案1
得分: 0
存在问题self.dimred_method
,如果它是None
,那么self.dimred_method.lower()
会引发AttributeError
,因为None
没有lower()
方法。
让我们先检查它是否为None
。
# ============ 减少嵌入维度 ============
if self.dimred_method is not None and self.dimred_method.lower() == 'pca':
# 矩阵化
N_samples = res_states.shape[0]
res_states = res_states.reshape(-1, res_states.shape[2])
# ..变换..
red_states = self._dim_red.fit_transform(res_states)
# ..然后恢复为张量形式
red_states = red_states.reshape(N_samples,-1,red_states.shape[1])
elif self.dimred_method is not None and self.dimred_method.lower() == 'tenpca':
red_states = self._dim_red.fit_transform(res_states)
else: # 跳过维度减少
red_states = res_states
英文:
There is a problem in self.dimred_method
, if it is None
, then self.dimred_method.lower()
raises an AttributeError
because None
doesn't have a lower()
method.
lets check if it is None
before.
# ============ Dimensionality reduction of the reservoir states ============
if self.dimred_method is not None and self.dimred_method.lower() == 'pca':
# matricize
N_samples = res_states.shape[0]
res_states = res_states.reshape(-1, res_states.shape[2])
# ..transform..
red_states = self._dim_red.fit_transform(res_states)
# ..and put back in tensor form
red_states = red_states.reshape(N_samples,-1,red_states.shape[1])
elif self.dimred_method is not None and self.dimred_method.lower() == 'tenpca':
red_states = self._dim_red.fit_transform(res_states)
else: # Skip dimensionality reduction
red_states = res_states
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论