Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'list' object has no attribute 'train' #8

Open
nilu33032 opened this issue Jun 1, 2019 · 1 comment
Open

'list' object has no attribute 'train' #8

nilu33032 opened this issue Jun 1, 2019 · 1 comment

Comments

@nilu33032
Copy link

nice code, but I seem to be running into problem when going through the 2nd generation (1st gen works fine), the train_network will throw an error: 'list' object has no attribute ' train'.

so basically -----

def train_network(networks):
for network in networks:
network.train() <---- 'list' has no attribute 'train' error.
pbar.update(1)

btw the database I have hardcoded it in the train, so it's not here

@xWuWux
Copy link

xWuWux commented Dec 9, 2023

The error message "'list' object has no attribute 'train'" suggests that the variable networks is a list, and the code is trying to call the train method on this list. However, the intention is likely to iterate over individual network objects within the list and call the train method on each of them.

Code Analysis:
Here, the networks parameter is expected to be a list of network objects. The code iterates through each element in the list (for network in networks) and attempts to call the train method on each element.

Probable Cause:
The error may occur if, during the second generation, the list networks is not containing instances of the Network class as expected but is instead a list of lists or other data structures.

Suggestions:
Ensure Consistency in networks:

Check the code that generates the networks list, especially during the second generation.
Verify that networks is a list of Network instances, not a list of lists or other data types.
Logging for Debugging:

Introduce logging statements in the code to print the type of each element in networks during the second generation.
This can help identify what type of objects are present in the list.
def train_network(networks): for network in networks: print(f"Type of network: {type(network)}") network.train() pbar.update(1)

Error Handling:

Implement error handling to gracefully handle cases where the elements in networks are not of the expected type.
For example, use if isinstance(network, Network): to check if an element is an instance of the Network class before calling the train method.
def train_network(networks): for network in networks: if isinstance(network, Network): network.train() pbar.update(1) else: print(f"Skipping non-Network element: {network}")
By addressing these suggestions, you can identify and resolve the issue causing the "'list' object has no attribute 'train'" error during the second generation of training.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants