ykamikawa / tf-keras-segnet Goto Github PK
View Code? Open in Web Editor NEWSegNet including indices pooling for Semantic Segmentation with tensorflow and keras
SegNet including indices pooling for Semantic Segmentation with tensorflow and keras
Hi,
I couldn't find myLayers.py in your repo, kindly can you forward?
is myLayers.py and layers.py are same??
I look forward for the response.
Thanks,
Anil
I don't fully understand the following operations to extract the indexes "y" and "x" form the agmax tensor. Could you elaborate a little on how did you get the following expressions?:
y = mask // (output_shape[2] * output_shape[3])
x = (mask // output_shape[3]) % output_shape[2]
Thank you very much
Pedro
I'm trying segnet model with input tensor shape 224x224x3, but Im getting the error "Input to reshape is a tensor with 100352 values, but the requested shape has 401408". Can anyone help me, I'm struck with that problem
Did anyone get this error please? I need help
Hey guys,
I am working on a project and try to use the SegNet architecture - and as I want to work on local host and on a distributed multi-server environment (got access to some GPUs) I want to work with Estimators.
But for this I have to switch from native keras
from keras.models import Model
from keras.layers import Input
from keras.layers.core import Activation, Reshape
from keras.layers.convolutional import Convolution2D
from keras.layers.normalization import BatchNormalization
to tensorflow-gpu 1.13.1 (pip3 install tensorflow-gpu) with tf.keras:
import tensorflow as tf
Convolution2D = tf.keras.layers.Convolution2D
BatchNormalization = tf.keras.layers.BatchNormalization
Activation = tf.keras.layers.Activation
Then I reduced the model and changed the output (as I have my labels in another format) to get my pipeline running at first:
def model(input_shape, n_labels, kernel=3, pool_size=(2, 2), output_mode="softmax"):
Convolution2D = tf.keras.layers.Convolution2D
BatchNormalization = tf.keras.layers.BatchNormalization
Activation = tf.keras.layers.Activation
# Encoder
inputs = tf.keras.layers.Input(shape=input_shape)
conv_1 = Convolution2D(64, (kernel, kernel), padding="same")(inputs)
conv_1 = BatchNormalization()(conv_1)
conv_1 = Activation("relu")(conv_1)
conv_2 = Convolution2D(64, (kernel, kernel), padding="same")(conv_1)
conv_2 = BatchNormalization()(conv_2)
conv_2 = Activation("relu")(conv_2)
# pool_1, mask_1 = MaxPoolingWithArgmax2D(pool_size)(conv_2)
# unpool_5 = MaxUnpooling2D(pool_size)([pool_1, mask_1])
conv_25 = Convolution2D(64, (kernel, kernel), padding="same")(conv_2)
conv_25 = BatchNormalization()(conv_25)
conv_25 = Activation("relu")(conv_25)
conv_26 = Convolution2D(n_labels, (1, 1), padding="valid")(conv_25)
conv_26 = BatchNormalization()(conv_26)
conv_26 = tf.keras.layers.Reshape(
(input_shape[0], input_shape[1], n_labels),
input_shape=(input_shape[0], input_shape[1], n_labels))(conv_26)
outputs = Activation(output_mode)(conv_26)
print("Building decoder done...")
model = tf.keras.models.Model(inputs=inputs, outputs=outputs, name="SegNet")
return model
This is working so far! Also with tf.keras instead of native keras!!
Now i want to check if upsampling with indices is working and therefore uncomment
pool_1, mask_1 = MaxPoolingWithArgmax2D(pool_size)(conv_2)
unpool_5 = MaxUnpooling2D(pool_size)([pool_1, mask_1])
and change input of conv_25 to unpool_5
conv_25 = Convolution2D(64, (kernel, kernel), padding="same")(unpool_5)
so this should downsample and upsample my tensors once.
But now it get following error in line of conv_25:
"ValueError: The channel dimension of the inputs should be defined. Found None
."
Can anybody please help me with this behavior!
Best regards,
Matt
I notice you do not have a license. Am I allowed to adapt your code for my own project and have my own license? The license does not restrict anyone's use, but my institution requires all of our work to have a general license for public use.
Hi, I have a problem.
I don´t know how to run this project.
When I run
train.py ,
I give: ValueError: Invalid file path or buffer object type: <class 'NoneType'>
I hope that someone can help me.
Thanks
when i run ,it display the error:
module 'keras.backend' has no attribute 'tf'
can you help me
Is there anyone who meet this problem"The channel dimension of the inputs should be defined. Found None".
I meet this problem in 'unpool_1 = MaxUnpooling2D(pool_size)([pool_5, mask_5])'.Who can help me ?Thinks
Hi!
I notice there are no licenses attached to your repository. Would you mind if I included your model implementation in one of my projects (while accrediting you of course)?
Are you aware of a way to make myLayers.py compatible with theano? Any help would be appreciated
There's a problem with me.
For some reason my "image_dim_ordering": is "th" and I don't know how the layers.py code works.
Can anybody show the MaxPoolingWithArgmax2D & MaxUnpooling2D code when input shape is ( channels, height, width )?
Can anyone help? Thanks a lot.
Hi,
I am trying to run the demo code (default parameters on LIP dataset). However, after printing the network structure, it prints the following error message:
`==================================================================================================
Total params: 29,460,260
Trainable params: 29,444,348
Non-trainable params: 15,912
None
Epoch 1/10
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\ProgramData\Anaconda3\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras-2.0.9-py3.6.egg\keras\utils\data_utils.py", line 630, in data_generator_task
generator_output = next(self._generator)
File "C:\Users\Baris\Desktop\SegNet-master\generator.py", line 24, in data_gen_small
original_img = cv2.imread(img_dir + lists.iloc[i, 0]+".jpg")[:, :, ::-1]
TypeError: 'NoneType' object is not subscriptable
Traceback (most recent call last):
File "SegNet.py", line 225, in
segnet.fit_generator(train_gen, steps_per_epoch=args.epoch_steps, epochs=args.n_epochs, validation_data=val_gen, validation_steps=args.val_steps)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras-2.0.9-py3.6.egg\keras\legacy\interfaces.py", line 87, in wrapper
File "C:\ProgramData\Anaconda3\lib\site-packages\keras-2.0.9-py3.6.egg\keras\engine\training.py", line 2048, in fit_generator
StopIteration`
What could be the problem?
请问您有训练好的h5模型么,我想用于做预训练
InvalidArgumentError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1321 try:
-> 1322 return fn(*args)
1323 except errors.OpError as e:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1306 return self._call_tf_sessionrun(
-> 1307 options, feed_dict, fetch_list, target_list, run_metadata)
1308
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
1408 self._session, options, feed_dict, fetch_list, target_list,
-> 1409 run_metadata)
1410 else:
InvalidArgumentError: Invalid indices: [32768,0] = [1, 33, 0, 0] does not index into [5,32,32,512]
[[Node: max_unpooling2d_1/max_unpooling2d_1/ScatterNd = ScatterNd[T=DT_FLOAT, Tindices=DT_INT32, _class=["loc:@train...d/GatherNd"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](max_unpooling2d_1/max_unpooling2d_1/transpose, max_unpooling2d_1/max_unpooling2d_1/Reshape_2, max_unpooling2d_1/max_unpooling2d_1/ScatterNd/shape)]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
in ()
----> 1 history = model.fit(X_train, y_train, validation_split=0.10, epochs=50, batch_size=5)
/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
1703 initial_epoch=initial_epoch,
1704 steps_per_epoch=steps_per_epoch,
-> 1705 validation_steps=validation_steps)
1706
1707 def evaluate(self, x=None, y=None,
/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in _fit_loop(self, f, ins, out_labels, batch_size, epochs, verbose, callbacks, val_f, val_ins, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps)
1234 ins_batch[i] = ins_batch[i].toarray()
1235
-> 1236 outs = f(ins_batch)
1237 if not isinstance(outs, list):
1238 outs = [outs]
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in call(self, inputs)
2480 session = get_session()
2481 updated = session.run(fetches=fetches, feed_dict=feed_dict,
-> 2482 **self.session_kwargs)
2483 return updated[:len(self.outputs)]
2484
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
898 try:
899 result = self._run(None, fetches, feed_dict, options_ptr,
--> 900 run_metadata_ptr)
901 if run_metadata:
902 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1133 if final_fetches or final_targets or (handle and feed_dict_tensor):
1134 results = self._do_run(handle, final_targets, final_fetches,
-> 1135 feed_dict_tensor, options, run_metadata)
1136 else:
1137 results = []
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1314 if handle is None:
1315 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1316 run_metadata)
1317 else:
1318 return self._do_call(_prun_fn, handle, feeds, fetches)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1333 except KeyError:
1334 pass
-> 1335 raise type(e)(node_def, op, message)
1336
1337 def _extend_graph(self):
InvalidArgumentError: Invalid indices: [32768,0] = [1, 33, 0, 0] does not index into [5,32,32,512]
[[Node: max_unpooling2d_1/max_unpooling2d_1/ScatterNd = ScatterNd[T=DT_FLOAT, Tindices=DT_INT32, _class=["loc:@train...d/GatherNd"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](max_unpooling2d_1/max_unpooling2d_1/transpose, max_unpooling2d_1/max_unpooling2d_1/Reshape_2, max_unpooling2d_1/max_unpooling2d_1/ScatterNd/shape)]]
Caused by op 'max_unpooling2d_1/max_unpooling2d_1/ScatterNd', defined at:
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py", line 16, in
app.launch_new_instance()
File "/usr/local/lib/python3.6/dist-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelapp.py", line 477, in start
ioloop.IOLoop.instance().start()
File "/usr/local/lib/python3.6/dist-packages/zmq/eventloop/ioloop.py", line 177, in start
super(ZMQIOLoop, self).start()
File "/usr/local/lib/python3.6/dist-packages/tornado/ioloop.py", line 888, in start
handler_func(fd_obj, events)
File "/usr/local/lib/python3.6/dist-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "/usr/local/lib/python3.6/dist-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python3.6/dist-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py", line 235, in dispatch_shell
handler(stream, idents, msg)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/ipkernel.py", line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2718, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2822, in run_ast_nodes
if self.run_code(code, result):
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2882, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
model = CreateSegNet((512,512,3),1)
File "", line 81, in CreateSegNet
unpool_1 = MaxUnpooling2D(pool_size)([pool_5, mask_5])
File "/usr/local/lib/python3.6/dist-packages/keras/engine/topology.py", line 619, in call
output = self.call(inputs, **kwargs)
File "", line 68, in call
ret = K.tf.scatter_nd(indices, values, output_shape)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 6702, in scatter_nd
"ScatterNd", indices=indices, updates=updates, shape=shape, name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
op_def=op_def)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1718, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): Invalid indices: [32768,0] = [1, 33, 0, 0] does not index into [5,32,32,512]
[[Node: max_unpooling2d_1/max_unpooling2d_1/ScatterNd = ScatterNd[T=DT_FLOAT, Tindices=DT_INT32, _class=["loc:@train...d/GatherNd"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](max_unpooling2d_1/max_unpooling2d_1/transpose, max_unpooling2d_1/max_unpooling2d_1/Reshape_2, max_unpooling2d_1/max_unpooling2d_1/ScatterNd/shape)]]
Hi,
In generator.py on line number 32, binarylab function is called. Can you please push that function too? I could not find its definition in the repo.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.