Code Monkey home page Code Monkey logo

Comments (7)

cepera-ang avatar cepera-ang commented on May 23, 2024 4

@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.

WenwenQi avatar WenwenQi commented on May 23, 2024 1

@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.

WenwenQi avatar WenwenQi commented on May 23, 2024

plus: I use LINUX system.

from kaggle_dstl_submission.

dmpetrov avatar dmpetrov commented on May 23, 2024

@WenwenQi, you can try to set image_dim_ordering to Theano th in ~/.keras/keras.json.

from kaggle_dstl_submission.

cug-chenhui avatar cug-chenhui commented on May 23, 2024

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.

cepera-ang avatar cepera-ang commented on May 23, 2024

@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.

degiorgig avatar degiorgig commented on May 23, 2024

@cepera-ang do you mind being more specific? sorry I'm also facing this issue

from kaggle_dstl_submission.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.