Echo State Network – AttributeError: ‘NoneType’ object has no attribute ‘lower’

huangapple go评论66阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月13日 19:53:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定