How to implement upsampling with mask(index) in tf.kerasHow to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?Finding the index of an item given a list containing it in PythonHow can I safely create a nested directory in Python?Accessing the index in 'for' loops?How do I sort a dictionary by value?How do I list all files of a directory?AveragePooling2D doesn't recognize a dtypeProblems with dimensions when fitting image in resnet model
Escape a backup date in a file name
How to Reset Passwords on Multiple Websites Easily?
How easy is it to start Magic from scratch?
Purchasing a ticket for someone else in another country?
For a non-Jew, is there a punishment for not observing the 7 Noahide Laws?
Avoiding estate tax by giving multiple gifts
Anatomically Correct Strange Women In Ponds Distributing Swords
Would a high gravity rocky planet be guaranteed to have an atmosphere?
Is exact Kanji stroke length important?
Type int? vs type int
Is `x >> pure y` equivalent to `liftM (const y) x`
Trouble understanding the speech of overseas colleagues
Why not increase contact surface when reentering the atmosphere?
Large drywall patch supports
Fine Tuning of the Universe
How to safely derail a train during transit?
How long to clear the 'suck zone' of a turbofan after start is initiated?
Is the destination of a commercial flight important for the pilot?
What is the opposite of 'gravitas'?
How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?
How does buying out courses with grant money work?
Why Were Madagascar and New Zealand Discovered So Late?
Failed to fetch jessie backports repository
How did Doctor Strange see the winning outcome in Avengers: Infinity War?
How to implement upsampling with mask(index) in tf.keras
How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?Finding the index of an item given a list containing it in PythonHow can I safely create a nested directory in Python?Accessing the index in 'for' loops?How do I sort a dictionary by value?How do I list all files of a directory?AveragePooling2D doesn't recognize a dtypeProblems with dimensions when fitting image in resnet model
I'm trying to build a SegNet with tf.keras, but meet some problem when I use tf.keras.layers.UpSampling. I don't know how to get the mask(index) of maxpooling and use it in tf.keras.layers.UpSampling.
I have seen the code of tf.keras.layers.UpSampling in https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/python/keras/layers/convolutional.py
It seems like that there is no implement of this function.
Then I try to find some alternative method and I got an implement in
https://github.com/ykamikawa/tf-keras-SegNet/blob/master/layers.py
I try this method with a simple test but meet some problem. The code is as follow:
from tensorflow.keras.layers import Layer
import tensorflow as tf
class MaxPoolingWithArgmax2D(Layer):
def __init__(
self,
pool_size=(2, 2),
strides=(2, 2),
padding='same',
**kwargs):
super(MaxPoolingWithArgmax2D, self).__init__(**kwargs)
self.padding = padding
self.pool_size = pool_size
self.strides = strides
def call(self, inputs, **kwargs):
padding = self.padding
pool_size = self.pool_size
strides = self.strides
ksize = [1, pool_size[0], pool_size[1], 1]
padding = padding.upper()
strides = [1, strides[0], strides[1], 1]
output, argmax = tf.nn.max_pool_with_argmax(
inputs,
ksize=ksize,
strides=strides,
padding=padding)
argmax = tf.cast(argmax, tf.float32)
return [output, argmax]
def compute_output_shape(self, input_shape):
ratio = (1, 2, 2, 1)
output_shape = [
dim//ratio[idx]
if dim is not None else None
for idx, dim in enumerate(input_shape)]
output_shape = tuple(output_shape)
return [output_shape, output_shape]
def compute_mask(self, inputs, mask=None):
return 2 * [None]
class MaxUnpooling2D(Layer):
def __init__(self, size=(2, 2), **kwargs):
super(MaxUnpooling2D, self).__init__(**kwargs)
self.size = size
def call(self, inputs, output_shape=None):
updates, mask = inputs[0], inputs[1]
with tf.variable_scope(self.name):
mask = tf.cast(mask, tf.int32)
# input_shape = tf.shape(updates, out_type='int32')
input_shape = updates.shape
# calculation new shape
if output_shape is None:
output_shape = (
input_shape[0],
input_shape[1]*self.size[0],
input_shape[2]*self.size[1],
input_shape[3])
self.output_shape1 = output_shape
# calculation indices for batch, height, width and feature maps
one_like_mask = tf.ones_like(mask, dtype='int32')
batch_shape = tf.concat(
[[input_shape[0]], [1], [1], [1]],
axis=0)
batch_range = tf.reshape(
tf.range(output_shape[0], dtype='int32'),
shape=batch_shape)
b = one_like_mask * batch_range
y = (mask // (output_shape[2] * output_shape[3]))
x = (mask // output_shape[3]) % output_shape[2]
feature_range = tf.range(output_shape[3], dtype='int32')
f = one_like_mask * feature_range
# transpose indices & reshape update values to one dimension
updates_size = tf.size(updates)
indices = tf.transpose(tf.reshape(
tf.stack([b, y, x, f]),
[4, updates_size]))
values = tf.reshape(updates, [updates_size])
ret = tf.scatter_nd(indices, values, output_shape)
return ret
def compute_output_shape(self, input_shape):
mask_shape = input_shape[1]
return (
mask_shape[0],
mask_shape[1]*self.size[0],
mask_shape[2]*self.size[1],
mask_shape[3]
)
def segmet(channels_in,channels_out):
inputs = tf.keras.layers.Input(shape=(None,None,channels_in))
outputs,mask = MaxPoolingWithArgmax2D()(inputs)
outputs = MaxUnpooling2D()([outputs,mask])
model = tf.keras.models.Model(inputs,outputs,name='segnet')
return model
if __name__ is '__main__':
model = segmet(3,6)
I meet an error as follow:
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/WWW/Desktop/untitled0.py', wdir='C:/Users/WWW/Desktop')
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 710, in runfile
execfile(filename, namespace)
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/WWW/Desktop/untitled0.py", line 108, in
model = segmet(3,6)
File "C:/Users/WWW/Desktop/untitled0.py", line 102, in segmet
outputs = MaxUnpooling2D()([outputs,mask])
File
"C:SoftAnaconda3libsite-packagestensorflowpythonkerasenginebase_layer.py",
line 757, in call
outputs = self.call(inputs, *args, **kwargs)
File "C:/Users/WWW/Desktop/untitled0.py", line 69, in call
axis=0)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsarray_ops.py",
line 1124, in concat
return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsgen_array_ops.py",
line 1202, in concat_v2
"ConcatV2", values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonframeworkop_def_library.py",
line 483, in _apply_op_helper
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have
types [, int32, int32, int32] that don't
all match.
Because the input in tf.keras model have no fixed size. So, the output_shape in the code above is [None, None, None, 3]. The function like tf.concat and tf.reshape cannot process 'None'. Then, tensorflow gives an error. I know why error happened, but I don't know how to fixed it.
Can anyone help me? Thanks.
python tf.keras
New contributor
add a comment |
I'm trying to build a SegNet with tf.keras, but meet some problem when I use tf.keras.layers.UpSampling. I don't know how to get the mask(index) of maxpooling and use it in tf.keras.layers.UpSampling.
I have seen the code of tf.keras.layers.UpSampling in https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/python/keras/layers/convolutional.py
It seems like that there is no implement of this function.
Then I try to find some alternative method and I got an implement in
https://github.com/ykamikawa/tf-keras-SegNet/blob/master/layers.py
I try this method with a simple test but meet some problem. The code is as follow:
from tensorflow.keras.layers import Layer
import tensorflow as tf
class MaxPoolingWithArgmax2D(Layer):
def __init__(
self,
pool_size=(2, 2),
strides=(2, 2),
padding='same',
**kwargs):
super(MaxPoolingWithArgmax2D, self).__init__(**kwargs)
self.padding = padding
self.pool_size = pool_size
self.strides = strides
def call(self, inputs, **kwargs):
padding = self.padding
pool_size = self.pool_size
strides = self.strides
ksize = [1, pool_size[0], pool_size[1], 1]
padding = padding.upper()
strides = [1, strides[0], strides[1], 1]
output, argmax = tf.nn.max_pool_with_argmax(
inputs,
ksize=ksize,
strides=strides,
padding=padding)
argmax = tf.cast(argmax, tf.float32)
return [output, argmax]
def compute_output_shape(self, input_shape):
ratio = (1, 2, 2, 1)
output_shape = [
dim//ratio[idx]
if dim is not None else None
for idx, dim in enumerate(input_shape)]
output_shape = tuple(output_shape)
return [output_shape, output_shape]
def compute_mask(self, inputs, mask=None):
return 2 * [None]
class MaxUnpooling2D(Layer):
def __init__(self, size=(2, 2), **kwargs):
super(MaxUnpooling2D, self).__init__(**kwargs)
self.size = size
def call(self, inputs, output_shape=None):
updates, mask = inputs[0], inputs[1]
with tf.variable_scope(self.name):
mask = tf.cast(mask, tf.int32)
# input_shape = tf.shape(updates, out_type='int32')
input_shape = updates.shape
# calculation new shape
if output_shape is None:
output_shape = (
input_shape[0],
input_shape[1]*self.size[0],
input_shape[2]*self.size[1],
input_shape[3])
self.output_shape1 = output_shape
# calculation indices for batch, height, width and feature maps
one_like_mask = tf.ones_like(mask, dtype='int32')
batch_shape = tf.concat(
[[input_shape[0]], [1], [1], [1]],
axis=0)
batch_range = tf.reshape(
tf.range(output_shape[0], dtype='int32'),
shape=batch_shape)
b = one_like_mask * batch_range
y = (mask // (output_shape[2] * output_shape[3]))
x = (mask // output_shape[3]) % output_shape[2]
feature_range = tf.range(output_shape[3], dtype='int32')
f = one_like_mask * feature_range
# transpose indices & reshape update values to one dimension
updates_size = tf.size(updates)
indices = tf.transpose(tf.reshape(
tf.stack([b, y, x, f]),
[4, updates_size]))
values = tf.reshape(updates, [updates_size])
ret = tf.scatter_nd(indices, values, output_shape)
return ret
def compute_output_shape(self, input_shape):
mask_shape = input_shape[1]
return (
mask_shape[0],
mask_shape[1]*self.size[0],
mask_shape[2]*self.size[1],
mask_shape[3]
)
def segmet(channels_in,channels_out):
inputs = tf.keras.layers.Input(shape=(None,None,channels_in))
outputs,mask = MaxPoolingWithArgmax2D()(inputs)
outputs = MaxUnpooling2D()([outputs,mask])
model = tf.keras.models.Model(inputs,outputs,name='segnet')
return model
if __name__ is '__main__':
model = segmet(3,6)
I meet an error as follow:
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/WWW/Desktop/untitled0.py', wdir='C:/Users/WWW/Desktop')
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 710, in runfile
execfile(filename, namespace)
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/WWW/Desktop/untitled0.py", line 108, in
model = segmet(3,6)
File "C:/Users/WWW/Desktop/untitled0.py", line 102, in segmet
outputs = MaxUnpooling2D()([outputs,mask])
File
"C:SoftAnaconda3libsite-packagestensorflowpythonkerasenginebase_layer.py",
line 757, in call
outputs = self.call(inputs, *args, **kwargs)
File "C:/Users/WWW/Desktop/untitled0.py", line 69, in call
axis=0)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsarray_ops.py",
line 1124, in concat
return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsgen_array_ops.py",
line 1202, in concat_v2
"ConcatV2", values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonframeworkop_def_library.py",
line 483, in _apply_op_helper
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have
types [, int32, int32, int32] that don't
all match.
Because the input in tf.keras model have no fixed size. So, the output_shape in the code above is [None, None, None, 3]. The function like tf.concat and tf.reshape cannot process 'None'. Then, tensorflow gives an error. I know why error happened, but I don't know how to fixed it.
Can anyone help me? Thanks.
python tf.keras
New contributor
add a comment |
I'm trying to build a SegNet with tf.keras, but meet some problem when I use tf.keras.layers.UpSampling. I don't know how to get the mask(index) of maxpooling and use it in tf.keras.layers.UpSampling.
I have seen the code of tf.keras.layers.UpSampling in https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/python/keras/layers/convolutional.py
It seems like that there is no implement of this function.
Then I try to find some alternative method and I got an implement in
https://github.com/ykamikawa/tf-keras-SegNet/blob/master/layers.py
I try this method with a simple test but meet some problem. The code is as follow:
from tensorflow.keras.layers import Layer
import tensorflow as tf
class MaxPoolingWithArgmax2D(Layer):
def __init__(
self,
pool_size=(2, 2),
strides=(2, 2),
padding='same',
**kwargs):
super(MaxPoolingWithArgmax2D, self).__init__(**kwargs)
self.padding = padding
self.pool_size = pool_size
self.strides = strides
def call(self, inputs, **kwargs):
padding = self.padding
pool_size = self.pool_size
strides = self.strides
ksize = [1, pool_size[0], pool_size[1], 1]
padding = padding.upper()
strides = [1, strides[0], strides[1], 1]
output, argmax = tf.nn.max_pool_with_argmax(
inputs,
ksize=ksize,
strides=strides,
padding=padding)
argmax = tf.cast(argmax, tf.float32)
return [output, argmax]
def compute_output_shape(self, input_shape):
ratio = (1, 2, 2, 1)
output_shape = [
dim//ratio[idx]
if dim is not None else None
for idx, dim in enumerate(input_shape)]
output_shape = tuple(output_shape)
return [output_shape, output_shape]
def compute_mask(self, inputs, mask=None):
return 2 * [None]
class MaxUnpooling2D(Layer):
def __init__(self, size=(2, 2), **kwargs):
super(MaxUnpooling2D, self).__init__(**kwargs)
self.size = size
def call(self, inputs, output_shape=None):
updates, mask = inputs[0], inputs[1]
with tf.variable_scope(self.name):
mask = tf.cast(mask, tf.int32)
# input_shape = tf.shape(updates, out_type='int32')
input_shape = updates.shape
# calculation new shape
if output_shape is None:
output_shape = (
input_shape[0],
input_shape[1]*self.size[0],
input_shape[2]*self.size[1],
input_shape[3])
self.output_shape1 = output_shape
# calculation indices for batch, height, width and feature maps
one_like_mask = tf.ones_like(mask, dtype='int32')
batch_shape = tf.concat(
[[input_shape[0]], [1], [1], [1]],
axis=0)
batch_range = tf.reshape(
tf.range(output_shape[0], dtype='int32'),
shape=batch_shape)
b = one_like_mask * batch_range
y = (mask // (output_shape[2] * output_shape[3]))
x = (mask // output_shape[3]) % output_shape[2]
feature_range = tf.range(output_shape[3], dtype='int32')
f = one_like_mask * feature_range
# transpose indices & reshape update values to one dimension
updates_size = tf.size(updates)
indices = tf.transpose(tf.reshape(
tf.stack([b, y, x, f]),
[4, updates_size]))
values = tf.reshape(updates, [updates_size])
ret = tf.scatter_nd(indices, values, output_shape)
return ret
def compute_output_shape(self, input_shape):
mask_shape = input_shape[1]
return (
mask_shape[0],
mask_shape[1]*self.size[0],
mask_shape[2]*self.size[1],
mask_shape[3]
)
def segmet(channels_in,channels_out):
inputs = tf.keras.layers.Input(shape=(None,None,channels_in))
outputs,mask = MaxPoolingWithArgmax2D()(inputs)
outputs = MaxUnpooling2D()([outputs,mask])
model = tf.keras.models.Model(inputs,outputs,name='segnet')
return model
if __name__ is '__main__':
model = segmet(3,6)
I meet an error as follow:
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/WWW/Desktop/untitled0.py', wdir='C:/Users/WWW/Desktop')
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 710, in runfile
execfile(filename, namespace)
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/WWW/Desktop/untitled0.py", line 108, in
model = segmet(3,6)
File "C:/Users/WWW/Desktop/untitled0.py", line 102, in segmet
outputs = MaxUnpooling2D()([outputs,mask])
File
"C:SoftAnaconda3libsite-packagestensorflowpythonkerasenginebase_layer.py",
line 757, in call
outputs = self.call(inputs, *args, **kwargs)
File "C:/Users/WWW/Desktop/untitled0.py", line 69, in call
axis=0)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsarray_ops.py",
line 1124, in concat
return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsgen_array_ops.py",
line 1202, in concat_v2
"ConcatV2", values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonframeworkop_def_library.py",
line 483, in _apply_op_helper
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have
types [, int32, int32, int32] that don't
all match.
Because the input in tf.keras model have no fixed size. So, the output_shape in the code above is [None, None, None, 3]. The function like tf.concat and tf.reshape cannot process 'None'. Then, tensorflow gives an error. I know why error happened, but I don't know how to fixed it.
Can anyone help me? Thanks.
python tf.keras
New contributor
I'm trying to build a SegNet with tf.keras, but meet some problem when I use tf.keras.layers.UpSampling. I don't know how to get the mask(index) of maxpooling and use it in tf.keras.layers.UpSampling.
I have seen the code of tf.keras.layers.UpSampling in https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/python/keras/layers/convolutional.py
It seems like that there is no implement of this function.
Then I try to find some alternative method and I got an implement in
https://github.com/ykamikawa/tf-keras-SegNet/blob/master/layers.py
I try this method with a simple test but meet some problem. The code is as follow:
from tensorflow.keras.layers import Layer
import tensorflow as tf
class MaxPoolingWithArgmax2D(Layer):
def __init__(
self,
pool_size=(2, 2),
strides=(2, 2),
padding='same',
**kwargs):
super(MaxPoolingWithArgmax2D, self).__init__(**kwargs)
self.padding = padding
self.pool_size = pool_size
self.strides = strides
def call(self, inputs, **kwargs):
padding = self.padding
pool_size = self.pool_size
strides = self.strides
ksize = [1, pool_size[0], pool_size[1], 1]
padding = padding.upper()
strides = [1, strides[0], strides[1], 1]
output, argmax = tf.nn.max_pool_with_argmax(
inputs,
ksize=ksize,
strides=strides,
padding=padding)
argmax = tf.cast(argmax, tf.float32)
return [output, argmax]
def compute_output_shape(self, input_shape):
ratio = (1, 2, 2, 1)
output_shape = [
dim//ratio[idx]
if dim is not None else None
for idx, dim in enumerate(input_shape)]
output_shape = tuple(output_shape)
return [output_shape, output_shape]
def compute_mask(self, inputs, mask=None):
return 2 * [None]
class MaxUnpooling2D(Layer):
def __init__(self, size=(2, 2), **kwargs):
super(MaxUnpooling2D, self).__init__(**kwargs)
self.size = size
def call(self, inputs, output_shape=None):
updates, mask = inputs[0], inputs[1]
with tf.variable_scope(self.name):
mask = tf.cast(mask, tf.int32)
# input_shape = tf.shape(updates, out_type='int32')
input_shape = updates.shape
# calculation new shape
if output_shape is None:
output_shape = (
input_shape[0],
input_shape[1]*self.size[0],
input_shape[2]*self.size[1],
input_shape[3])
self.output_shape1 = output_shape
# calculation indices for batch, height, width and feature maps
one_like_mask = tf.ones_like(mask, dtype='int32')
batch_shape = tf.concat(
[[input_shape[0]], [1], [1], [1]],
axis=0)
batch_range = tf.reshape(
tf.range(output_shape[0], dtype='int32'),
shape=batch_shape)
b = one_like_mask * batch_range
y = (mask // (output_shape[2] * output_shape[3]))
x = (mask // output_shape[3]) % output_shape[2]
feature_range = tf.range(output_shape[3], dtype='int32')
f = one_like_mask * feature_range
# transpose indices & reshape update values to one dimension
updates_size = tf.size(updates)
indices = tf.transpose(tf.reshape(
tf.stack([b, y, x, f]),
[4, updates_size]))
values = tf.reshape(updates, [updates_size])
ret = tf.scatter_nd(indices, values, output_shape)
return ret
def compute_output_shape(self, input_shape):
mask_shape = input_shape[1]
return (
mask_shape[0],
mask_shape[1]*self.size[0],
mask_shape[2]*self.size[1],
mask_shape[3]
)
def segmet(channels_in,channels_out):
inputs = tf.keras.layers.Input(shape=(None,None,channels_in))
outputs,mask = MaxPoolingWithArgmax2D()(inputs)
outputs = MaxUnpooling2D()([outputs,mask])
model = tf.keras.models.Model(inputs,outputs,name='segnet')
return model
if __name__ is '__main__':
model = segmet(3,6)
I meet an error as follow:
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/WWW/Desktop/untitled0.py', wdir='C:/Users/WWW/Desktop')
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 710, in runfile
execfile(filename, namespace)
File
"C:SoftAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/WWW/Desktop/untitled0.py", line 108, in
model = segmet(3,6)
File "C:/Users/WWW/Desktop/untitled0.py", line 102, in segmet
outputs = MaxUnpooling2D()([outputs,mask])
File
"C:SoftAnaconda3libsite-packagestensorflowpythonkerasenginebase_layer.py",
line 757, in call
outputs = self.call(inputs, *args, **kwargs)
File "C:/Users/WWW/Desktop/untitled0.py", line 69, in call
axis=0)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsarray_ops.py",
line 1124, in concat
return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonopsgen_array_ops.py",
line 1202, in concat_v2
"ConcatV2", values=values, axis=axis, name=name)
File
"C:SoftAnaconda3libsite-packagestensorflowpythonframeworkop_def_library.py",
line 483, in _apply_op_helper
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have
types [, int32, int32, int32] that don't
all match.
Because the input in tf.keras model have no fixed size. So, the output_shape in the code above is [None, None, None, 3]. The function like tf.concat and tf.reshape cannot process 'None'. Then, tensorflow gives an error. I know why error happened, but I don't know how to fixed it.
Can anyone help me? Thanks.
python tf.keras
python tf.keras
New contributor
New contributor
edited Mar 21 at 17:54
Sagar P. Ghagare
5452921
5452921
New contributor
asked Mar 21 at 16:00
WenchaoWenchao
11
11
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Wenchao is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284571%2fhow-to-implement-upsampling-with-maskindex-in-tf-keras%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Wenchao is a new contributor. Be nice, and check out our Code of Conduct.
Wenchao is a new contributor. Be nice, and check out our Code of Conduct.
Wenchao is a new contributor. Be nice, and check out our Code of Conduct.
Wenchao is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284571%2fhow-to-implement-upsampling-with-maskindex-in-tf-keras%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown