hnhuang commented on issue #7582: Gluon GPU memory efficiency
URL: 
https://github.com/apache/incubator-mxnet/issues/7582#issuecomment-324483265
 
 
   The memory consumption is the same as before. And I don't gain any 
performance... Here is the code. I do call vgg_net.hybridize() in the main 
program.
   
   ```
   class get_vgg16(gluon.HybridBlock):
       def __init__(self, max_radius, **kwargs):
           super(get_vgg16, self).__init__(**kwargs)
           with self.name_scope():
               # c2 layer
               self.c2 = nn.HybridSequential(prefix='c2')
               self.c2.add(nn.Conv3D(64, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c2.add(nn.Conv3D(64, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c2.add(nn.MaxPool3D(pool_size=(2, 2, 2), strides = (2, 2, 
2)))
               self.c2.add(nn.Conv3D(128, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c2.add(nn.Conv3D(128, kernel_size = 3, padding = 1, 
activation='relu'))
               # c3 layer
               self.c3 = nn.HybridSequential(prefix='c3')
               self.c3.add(nn.MaxPool3D(pool_size=(2, 2, 2), strides = (2, 2, 
2)))
               self.c3.add(nn.Conv3D(256, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c3.add(nn.Conv3D(256, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c3.add(nn.Conv3D(256, kernel_size = 3, padding = 1, 
activation='relu'))
               # c4 layer
               self.c4 = nn.HybridSequential(prefix='c4')
               self.c4.add(nn.MaxPool3D(pool_size=(2, 2, 2), strides = (2, 2, 
2)))
               self.c4.add(nn.Conv3D(512, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c4.add(nn.Conv3D(512, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c4.add(nn.Conv3D(512, kernel_size = 3, padding = 1, 
activation='relu'))
               # c5 layer
               self.c5 = nn.HybridSequential(prefix='c5')
               self.c5.add(nn.MaxPool3D(pool_size=(2, 2, 2), strides = (2, 2, 
2)))
               self.c5.add(nn.Conv3D(512, kernel_size = 3, padding = 1, 
activation='relu'))
               self.c5.add(nn.Conv3D(512, kernel_size = 3, padding = 1, 
activation='relu'))
               # u5 layer
               self.c5.add(nn.Conv3D(128, kernel_size = 1, padding = 0, 
activation='relu'))
               self.c5.add(nn.Conv3DTranspose(128, kernel_size = 2, strides = 
(2, 2, 2), activation='relu'))
               # x4 layer
               self.x4 = nn.HybridSequential(prefix='x4')
               self.x4.add(nn.Conv3D(128, kernel_size = 1, padding = 0, 
activation='relu'))
               # u4 layer
               self.u4 = nn.HybridSequential(prefix='u4')
               self.u4.add(nn.Conv3DTranspose(128, kernel_size = 2, strides = 
(2, 2, 2), activation='relu'))
               # x3 layer
               self.x3 = nn.HybridSequential(prefix='x3')
               self.x3.add(nn.Conv3D(128, kernel_size = 1, padding = 0, 
activation='relu'))
               # u3 layer
               self.u3 = nn.HybridSequential(prefix='u3')
               self.u3.add(nn.Conv3DTranspose(128, kernel_size = 2, strides = 
(2, 2, 2), activation='relu'))
               # x2 layer
               self.x2 = nn.HybridSequential(prefix='x2')
               self.x2.add(nn.Conv3D(128, kernel_size = 1, padding = 0, 
activation='relu'))
               # Block 7
               self.net = nn.HybridSequential(prefix='net')
               self.net.add(nn.Conv3D(256, kernel_size = 3, padding = 1, 
activation='relu'))
               self.net.add(nn.Conv3D(4096, kernel_size = 1, padding = 0, 
activation='relu'))
               self.net.add(nn.Conv3D(4096, kernel_size = 1, padding = 0, 
activation='relu'))
               self.net.add(nn.Conv3D(max_radius, kernel_size = 1, 
activation='sigmoid'))
       def hybrid_forward(self, F, x):
           x_c2 = self.c2(x)
           x_c3 = self.c3(x_c2)
           x_c4 = self.c4(x_c3)
           x_u5 = self.c5(x_c4)
           x4 = self.x4(x_c4) + x_u5
           x_u4 = self.u4(x4)
           x3 = self.x3(x_c3) + x_u4
           x_u3 = self.u3(x3)
           x2 = self.x2(x_c2) + x_u3
           res = self.net(x2)
           return res 
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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