question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

for loop to add layers with multiple choices is not working

See original GitHub issue

Hi,

I was looking for examples about how to add multiples layers using a for loop and I got something similar to this code (line 85). Did you notice the for loop is not working how it suppose to be? I mean, I want that depending on the choice in range add some layers with a different choice for each layer but instead, I’m getting yeah multiple layers but all of them with the same choice.

Here an example of the results I got after running minimize:

model = Sequential([
    # first layer out of the loop:
    layers.Conv2D(filters=256, kernel_size=(4, 4), activation='tanh', input_shape=(128, 128, 3)),
    layers.MaxPool2D(pool_size=(2,2)),
    layers.Dropout(0.7139834391535448),

   # second layer in the loop after for _ in range(2):
    layers.Conv2D(filters=128, kernel_size=(3, 3), activation='relu'), # << same filter and kernel
    layers.MaxPool2D(pool_size=(2,2)),
    layers.Dropout(0.48363463144260765), # << same dropout

    # third layer in the loop
    layers.Conv2D(filters=128, kernel_size=(3, 3), activation='relu'), # << same filter and kernel
    layers.MaxPool2D(pool_size=(2,2)),
    layers.Dropout(0.48363463144260765), # << same dropout

    layers.Flatten(),
    layers.Dense(256, activation='relu'),
    layers.Dropout(0.7692559015213345),
    layers.Dense(5, activation='sigmoid', name='predict')

What am I doing wrong? or shouldn’t I use a loop at all? Thanks!

Regards, David Molina

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
deKeijzercommented, Apr 23, 2019

@virtualdvid The last thing you could try is running my code and try to figure out if that works. A simple git clone should do, as everything (including the data) is in the repository. Unfortunately i’m unable to test the code myself due to some trouble with my current GPU setup. I thought the loops were working, but i might as well have not noticed it to be faulty. The code had been written in quite the hurry… Sorry to not be able to help you any further.

Good luck!

0reactions
virtualdvidcommented, Apr 23, 2019

@deKeijzer it works exactly the same, I just put it into a variable to get a “custom” name, you know hyperas named things in a confusing way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use a loop to add layers to the map that are not ...
Now I am trying to add an addAllLayers function, using a similar loop. Issue is, I don't really understand what the resetMap loop...
Read more >
Loop to add groups and layers based on user's checkbox choice
Logic of adding/removing layers can then go something like this: At each #exec click loop through all the checkboxes (not just selected).
Read more >
Loop animations - Google Web Designer Help
Loop the animation for multiple elements · Right-click the Events track (the first row of the timeline) where you want the animation to...
Read more >
Video: Create and change SmartArt - Microsoft Support
These SmartArt features work similarly across your Office apps. Add SmartArt. Select Insert > SmartArt. On the left, select the type of layout...
Read more >
Reusable Choices - Qualtrics
Multiple Choice Question · Matrix Table Question · Text Entry Question · Form Field Question ... CSV/TSV Upload Issues · Adding & Removing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found