feevos commented on issue #16736: Bug when iterating over HybridSequential 
elements 
URL: 
https://github.com/apache/incubator-mxnet/issues/16736#issuecomment-550172645
 
 
   Some additional information: it seems the error relates to how many times 
the initial input is passed from the conv layers. It is not directly related to 
the iteration over the HybridSequential container. 
   
   This works irrespective to what is the length of the kernel_sizes:
   
   ```Python
   class Demo(HybridBlock):
       def __init__(self, kernel_sizes = [3,3,3,3],**kwards):
           super().__init__(**kwards)
           
           with self.name_scope():
               self.net = gluon.nn.HybridSequential()
               for k in kernel_sizes:
                   tnet = gluon.nn.HybridSequential()
                   for _ in range(3):
                       tnet.add(gluon.nn.Conv2D(32,kernel_size=k,padding=1))
                   self.net.add(tnet)
       def hybrid_forward(self, F, input):
           x = input
           for conv in self.net:
               #x = x + conv(input)
               x = x + conv(x) ## <===== CHANGE HERE 
               
           return x
   ```
   Runs fine: 
   ```Python
   nfilters=32
   F = 256
   
   net = Demo(kernel_sizes=[3]*100)
   net.initialize()
   net.hybridize()
   xx = nd.random.uniform(shape=[7,nfilters,F,F])
   out = net(xx)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to