def forward_prop(): for l, l_info in enumerate(ConvModel.layer_info): func_name, func_args = l_info[0], l_info[1:] act_in = ConvModel.act_tensor[l] act_out, dz_out, maxpool_mask = None, None, None # perform layer-wise convolution operation if func_name == 'convolve3d': z_out_3d = Layers.convolve3d(act_in, ConvModel.w_tensor[l], ConvModel.b_tensor[l], func_args[0], func_args[1]) dz_out = Layers.drelu(np.array(z_out_3d)) act_out = Layers.relu(np.array(z_out_3d)) # perform mlp layer-wise forward pass operation if func_name == 'fc_layer': act_in = np.ravel(act_in) z_out = np.dot(act_in, ConvModel.w_tensor[l]) + ConvModel.b_tensor[l] act_out = getattr(Layers, func_args[0])(np.array(z_out)) dz_out = getattr(Layers, 'd' + func_args[0])(np.array(z_out)) # perform layer-wise pooling operation if func_name == 'maxpool3d': pool_outputs = Layers.maxpool3d(input=act_in, filter_dim=func_args[0], stride=func_args[1]) act_out = pool_outputs[0] maxpool_mask = pool_outputs[1] dz_out = Layers.drelu(np.array(act_out)) ConvModel.act_tensor[l + 1] = np.array(act_out) ConvModel.dz_tensor[l] = np.array(dz_out) ConvModel.maxpool_masks[l] = np.array(maxpool_mask)
def subsampled(inputs, reuse=False): # Less border effect inputs = Layers.pad(inputs) with tf.variable_scope('subsampled', reuse=reuse): conv1 = Layers.conv2d(inputs, 3, 32, 9, 1, 'SAME', 'conv1') norm1 = Layers.instance_norm(conv1) relu1 = Layers.relu(norm1) conv2 = Layers.conv2d(relu1, 32, 64, 3, 2, 'SAME', 'conv2') norm2 = Layers.instance_norm(conv2) relu2 = Layers.relu(norm2) conv3 = Layers.conv2d(relu2, 64, 128, 3, 2, 'SAME', 'conv3') norm3 = Layers.instance_norm(conv3) relu3 = Layers.relu(norm3) return relu3
def upsampling(inputs, reuse=False): with tf.variable_scope('upsampling', reuse=reuse): deconv1 = Layers.resize_conv2d(inputs, 128, 64, 3, 2, 'SAME', 'deconv1') denorm1 = Layers.instance_norm(deconv1) derelu1 = Layers.relu(denorm1) deconv2 = Layers.resize_conv2d(derelu1, 64, 32, 3, 2, 'SAME', 'deconv2') denorm2 = Layers.instance_norm(deconv2) derelu2 = Layers.relu(denorm2) deconv3 = Layers.resize_conv2d(derelu2, 32, 3, 9, 1, 'SAME', 'deconv3') denorm3 = Layers.instance_norm(deconv3) detanh3 = tf.nn.tanh(denorm3) y = (detanh3 + 1) * 127.5 # Remove the border effect y = Layers.remove_pad(y) return y