Commit d5dad129 authored by Peter Eastman's avatar Peter Eastman
Browse files

Fixed errors in computing layer output shapes and loading images

parent cce55b72
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -369,6 +369,7 @@ class ImageLoader(DataLoader):
      remainder = []
      for input_file in input_files:
        filename, extension = os.path.splitext(input_file)
        extension = extension.lower()
        # TODO(rbharath): Add support for more extensions
        if os.path.isdir(input_file):
          dirfiles = [
@@ -386,6 +387,7 @@ class ImageLoader(DataLoader):
          ]
          for zip_file in zip_files:
            _, extension = os.path.splitext(zip_file)
            extension = extension.lower()
            if extension in [".png", ".tif"]:
              image_files.append(zip_file)
        elif extension in [".png", ".tif"]:
@@ -405,6 +407,7 @@ class ImageLoader(DataLoader):
    images = []
    for image_file in image_files:
      _, extension = os.path.splitext(image_file)
      extension = extension.lower()
      if extension == ".png":
        image = misc.imread(image_file)
        images.append(image)
+27 −6
Original line number Diff line number Diff line
@@ -485,7 +485,6 @@ class Conv1D(Layer):
      `(10, 128)` for sequences of 10 vectors of 128-dimensional vectors,
      or `(None, 128)` for variable-length sequences of 128-dimensional vectors.

      TODO(LESWING): Calculate output shape at construction time
      Arguments:
          filters: Integer, the dimensionality of the output space
              (i.e. the number output of filters in the convolution).
@@ -541,6 +540,17 @@ class Conv1D(Layer):
    self.kernel_constraint = kernel_constraint
    self.bias_constraint = bias_constraint
    super(Conv1D, self).__init__(in_layers, **kwargs)
    try:
      parent_shape = self.in_layers[0].shape
      if isinstance(strides, int):
        strides = (strides,)
      if padding.lower() == 'same':
        self._shape = (parent_shape[0],
                       int(np.ceil(parent_shape[1] / strides[0])), filters)
      else:
        self._shape = (parent_shape[0], parent_shape[1] // strides[0], filters)
    except:
      pass

  def _build_layer(self):
    return tf.keras.layers.Conv1D(
@@ -1983,6 +1993,11 @@ class Conv2D(SharedVariableScope):
      strides = stride
      if isinstance(stride, int):
        strides = (stride, stride)
      if padding.lower() == 'same':
        self._shape = (parent_shape[0],
                       int(np.ceil(parent_shape[1] / strides[0])),
                       int(np.ceil(parent_shape[2] / strides[1])), num_outputs)
      else:
        self._shape = (parent_shape[0], parent_shape[1] // strides[0],
                       parent_shape[2] // strides[1], num_outputs)
    except:
@@ -2100,6 +2115,12 @@ class Conv3D(SharedVariableScope):
      strides = stride
      if isinstance(stride, int):
        strides = (stride, stride, stride)
      if padding.lower() == 'same':
        self._shape = (parent_shape[0],
                       int(np.ceil(parent_shape[1] / strides[0])),
                       int(np.ceil(parent_shape[2] / strides[1])),
                       int(np.ceil(parent_shape[3] / strides[2])), num_outputs)
      else:
        self._shape = (parent_shape[0], parent_shape[1] // strides[0],
                       parent_shape[2] // strides[1],
                       parent_shape[3] // strides[2], num_outputs)