Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions tensorlayer/layers/convolution/simplified_deconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def __init__(
self.b_init = b_init
self.in_channels = in_channels

# Attention: To build, we need not only the in_channels!
# if self.in_channels:
# self.build(None)
# self._built = True
# Attention: To build, we need not only the in_channels! Solved.
if self.in_channels is not None:
self.build(None)
self._built = True

logging.info(
"DeConv2d {}: n_filters: {} strides: {} padding: {} act: {} dilation: {}".format(
Expand Down Expand Up @@ -132,10 +132,13 @@ def build(self, inputs_shape):
# dtype=tf.float32,
name=self.name,
)
if self.data_format == "channels_first":
self.in_channels = inputs_shape[1]
if inputs_shape is not None:
self.in_channels = inputs_shape[1 if self.data_format == "channels_first" else -1]
elif self.in_channels is not None:
inputs_shape = [1, self.in_channels, 1, 1
] if self.data_format == "channels_first" else [1, 1, 1, self.in_channels]
else:
self.in_channels = inputs_shape[-1]
raise ValueError("Either inputs_shape or in_channels must be specified for build.")
_out = self.layer(
tf.convert_to_tensor(np.random.uniform(size=inputs_shape), dtype=np.float32)
) #np.random.uniform([1] + list(inputs_shape))) # initialize weights
Expand Down Expand Up @@ -206,12 +209,12 @@ def __init__(
self.data_format = data_format
self.W_init = W_init
self.b_init = b_init
self.in_channels = in_channels,
self.in_channels = in_channels

# Attention: To build, we need not only the in_channels!
# if self.in_channels:
# self.build(None)
# self._built = True
# Attention: To build, we need not only the in_channels! Solved.
if self.in_channels is not None:
self.build(None)
self._built = True

logging.info(
"DeConv3d %s: n_filters: %s strides: %s pad: %s act: %s" % (
Expand Down Expand Up @@ -252,16 +255,17 @@ def build(self, inputs_shape):
bias_initializer=self.b_init,
name=self.name,
)
if self.data_format == "channels_first":
self.in_channels = inputs_shape[1]
if inputs_shape is not None:
self.in_channels = inputs_shape[1 if self.data_format == "channels_first" else -1]
elif self.in_channels is not None:
inputs_shape = [1, self.in_channels, 1, 1, 1
] if self.data_format == "channels_first" else [1, 1, 1, 1, self.in_channels]
else:
self.in_channels = inputs_shape[-1]

raise ValueError("Either inputs_shape or in_channels must be specified for build.")
_out = self.layer(
tf.convert_to_tensor(np.random.uniform(size=inputs_shape), dtype=np.float32)
) #self.layer(np.random.uniform([1] + list(inputs_shape))) # initialize weights
outputs_shape = _out.shape
# self._add_weights(self.layer.weights)
self._trainable_weights = self.layer.weights

def forward(self, inputs):
Expand Down
2 changes: 1 addition & 1 deletion tensorlayer/layers/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ def forward(self, inputs):
if self.axes is None:
self.axes = [i for i in range(len(inputs.shape)) if i != self.channel_axis]

mean, var = tf.nn.moments(inputs, self.axes, keepdims=False)
if self.is_train:
# update moving_mean and moving_var
mean, var = tf.nn.moments(inputs, self.axes, keepdims=False)
self.moving_mean = moving_averages.assign_moving_average(
self.moving_mean, mean, self.decay, zero_debias=False
)
Expand Down