def compute_output_shape(self, input_shape): input_shape = tuple(tensor_shape.TensorShape(input_shape).as_list()) if self._output_shape is None: if context.executing_eagerly(): raise NotImplementedError x = K.placeholder(shape=input_shape) x = self.call(x) if isinstance(x, list): return [ tensor_shape.TensorShape(K.int_shape(x_elem)) for x_elem in x ] else: return tensor_shape.TensorShape(K.int_shape(x)) elif isinstance(self._output_shape, (tuple, list)): if isinstance(input_shape, list): num_samples = input_shape[0][0] else: num_samples = input_shape[0] if input_shape else None return tensor_shape.TensorShape((num_samples, ) + tuple(self._output_shape)) else: shape = self._output_shape(input_shape) if not isinstance(shape, (list, tuple)): raise ValueError( '`output_shape` function must return a tuple or a list of tuples.' ) if isinstance(shape, list): if isinstance(shape[0], int) or shape[0] is None: shape = tuple(shape) return tensor_shape.TensorShape(shape)
def _compute_output_shape(self, input_shape): input_shape = tuple(tensor_shape.TensorShape(input_shape).as_list()) if self._output_shape is None: x = K.placeholder(shape=input_shape) x = self.call(x) if isinstance(x, list): return [tensor_shape.TensorShape(K.int_shape(x_elem)) for x_elem in x] else: return tensor_shape.TensorShape(K.int_shape(x)) elif isinstance(self._output_shape, (tuple, list)): if isinstance(input_shape, list): num_samples = input_shape[0][0] else: num_samples = input_shape[0] if input_shape else None return tensor_shape.TensorShape((num_samples,) + tuple(self._output_shape)) else: shape = self._output_shape(input_shape) if not isinstance(shape, (list, tuple)): raise ValueError( '`output_shape` function must return a tuple or a list of tuples.') if isinstance(shape, list): if isinstance(shape[0], int) or shape[0] is None: shape = tuple(shape) return tensor_shape.TensorShape(shape)
def pooling_func(x): if pooltype == 1: return AveragePooling2D((2, 2), strides=(2, 2))(x) else: return MaxPooling2D((2, 2), strides = (2,2))(x) # get tensor representations of our images base_image = K.variable(preprocess_image(base_image_path, True, read_mode=read_mode)) style_reference_images = [] for style_path in style_image_paths: style_reference_images.append(K.variable(preprocess_image(style_path))) # this will contain our generated image combination_image = K.placeholder((1, img_width, img_height, 3)) image_tensors = [base_image] for style_image_tensor in style_reference_images: image_tensors.append(style_image_tensor) image_tensors.append(combination_image) nb_tensors = len(image_tensors) print("nb_tensors", nb_tensors) nb_style_images = nb_tensors - 2 # Content and Output image not considered # combine the various image into a single Keras tensor input_tensor = K.concatenate(image_tensors, axis=0) shape = (nb_tensors, img_width, img_height, 3) inp_shape = (img_width, img_height, 3)