Comments (7)
@leader80 there are two ways to organize image data: NCHW or channels_first and NHWC or channels_last. First N stands for N images in batch, C stands for channels and H, W is height and width of image. As you can see in the code, this network defaults to NCHW input (for example, look here https://github.com/ternaus/kaggle_dstl_submission/blob/master/src/unet_buildings.py#L63) and Theano backend used during training does the same too. It means that all convolutions change C axis of tensor (second place, index 1 starting from zero) and pooling layers change only H and W, thus concat_axis everywhere is 1, as we concat tensors of the same height and width and only different number of channels and batchnorm axis also 1 (along channels).
New versions of Keras use Tensorflow backend and Tensorflow uses NHWC by default because it is faster on CPU (sic!) (see discussion here). So this change messes up all the axes in the network. There are to ways dealing with it:
- first option, add old ordering option to Keras config file (lookup at google how to do it in current version), -
- second option, change input to be NHWC format and replace all concat and batch norm axes to -1.
That's it, hope this helps
from kaggle_dstl_submission.
@dmpetrov Thanks a lot.
I resolved this problem by set "unet_buildings.py" code :
up6 = merge([UpSampling2D(size=(2, 2))(conv5), conv4], mode='concat', concat_axis=1)
change "concat_axis=1" to "concat_axis= -1" to match [2, 14, 512] and [2, 14, 256].
from kaggle_dstl_submission.
plus: I use LINUX system.
from kaggle_dstl_submission.
@WenwenQi, you can try to set image_dim_ordering
to Theano th
in ~/.keras/keras.json
.
from kaggle_dstl_submission.
I meet the same question as you. and I change "concat_axis=1" to "concat_axis= -1" from up6 to up9, but I got an error as following:
File "/home/chen-h/PycharmProjects/3th kaggle_dstl_submission-master/kaggle_dstl_submission-master/src/unet_trees.py", line 250, in
model = get_unet0()
File "/home/chen-h/PycharmProjects/3th kaggle_dstl_submission-master/kaggle_dstl_submission-master/src/unet_trees.py", line 133, in get_unet0
conv9 = BatchNormalization(mode=0, axis=1)(crop9)
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 575, in call
self.build(input_shapes[0])
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/keras/layers/normalization.py", line 103, in build
constraint=self.gamma_constraint)
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
return func(*args, **kwargs)
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 396, in add_weight
weight = K.variable(initializer(shape),
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/keras/initializers.py", line 41, in call
return K.constant(1, shape=shape, dtype=dtype)
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 358, in constant
return tf.constant(value, dtype=dtype, shape=shape, name=name)
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 99, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/home/chen-h/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 421, in make_tensor_proto
(shape_size, nparray.size))
ValueError: Too many elements provided. Needed at most -16, but received 1
It seems to caused by the following code:
conv9 = Convolution2D(32, 3, 3, border_mode='same', init='he_uniform')(conv9)
crop9 = Cropping2D(cropping=((16, 16), (16, 16)))(conv9)
conv9 = BatchNormalization(mode=0, axis=1)(crop9)
Can you give me some advice?
thanks a lot.
from kaggle_dstl_submission.
@cug-chenhui you have to carefully check where do you place your channels and correct channel_axis everywhere starting from your input, then check every layer to the output. Or use the same channel as was originally intended :)
from kaggle_dstl_submission.
@cepera-ang do you mind being more specific? sorry I'm also facing this issue
from kaggle_dstl_submission.
Related Issues (20)
- Using real coordinates
- h5py.File doesn't have compression as argument? HOT 1
- Training at once for all classes HOT 1
- output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None HOT 3
- ValueError: "concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 1024, 14, 7), (None, 256, 14, 14)] HOT 2
- RGB implementation HOT 4
- Object detection question HOT 1
- TypeError: 'compression_opts' is an invalid keyword argument for this function(cache_train.py) HOT 1
- Running visualize error HOT 1
- How can I label my own images? HOT 1
- Thanks so much HOT 1
- How can I make this code work with images of 3 bands only? HOT 3
- why loss go up?
- model issue
- TypeError: 'compression' is an invalid keyword argument for this function HOT 2
- Reproducing Results Problem HOT 1
- make prediction on buildings is failing HOT 5
- Running code only with RGB images HOT 3
- Dimension of the traning set images HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaggle_dstl_submission.