question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hey,

I realized that only certain input_shapes seem to be working or I get a broadcast error. Operands could not be broadcast together with shapes

Do you know how I can easily fix this? I am working with (19,19,19) cubes atm These are the input_shapes that seem to be allowed:

(1,1,1) : ok
(2,2,2) : ok
(3,3,3) : ok
(4,4,4) : ok
(5,5,5) : ok
(6,6,6) : ok
(7,7,7) : ok
(8,8,8) : ok
(9,9,9) : Operands could not be broadcast together with shapes (3, 3, 3, 128) (2, 2, 2, 128)
(10,10,10) : Operands could not be broadcast together with shapes (3, 3, 3, 128) (2, 2, 2, 128)
(11,11,11) : Operands could not be broadcast together with shapes (3, 3, 3, 128) (2, 2, 2, 128)
12 : Operands could not be broadcast together with shapes (3, 3, 3, 512) (2, 2, 2, 512)
13 : ok
14 : ok
15 : ok
16 : ok
17 : Operands could not be broadcast together with shapes (5, 5, 5, 512) (3, 3, 3, 512)
18 : Operands could not be broadcast together with shapes (5, 5, 5, 512) (3, 3, 3, 512)
19 : Operands could not be broadcast together with shapes (5, 5, 5, 512) (3, 3, 3, 512)
20 : Operands could not be broadcast together with shapes (5, 5, 5, 512) (3, 3, 3, 512)
21 : Operands could not be broadcast together with shapes (3, 3, 3, 1024) (2, 2, 2, 1024)
22 : Operands could not be broadcast together with shapes (3, 3, 3, 1024) (2, 2, 2, 1024)
23 : Operands could not be broadcast together with shapes (3, 3, 3, 1024) (2, 2, 2, 1024)
24 : Operands could not be broadcast together with shapes (3, 3, 3, 1024) (2, 2, 2, 1024)
25 : Operands could not be broadcast together with shapes (7, 7, 7, 512) (4, 4, 4, 512)
26 : Operands could not be broadcast together with shapes (7, 7, 7, 512) (4, 4, 4, 512)
27 : Operands could not be broadcast together with shapes (7, 7, 7, 512) (4, 4, 4, 512)
28 : Operands could not be broadcast together with shapes (7, 7, 7, 512) (4, 4, 4, 512)
29 : ok
30 : ok
31 : ok
32 : ok
33 : Operands could not be broadcast together with shapes (9, 9, 9, 512) (5, 5, 5, 512)
34 : Operands could not be broadcast together with shapes (9, 9, 9, 512) (5, 5, 5, 512)
35 : Operands could not be broadcast together with shapes (9, 9, 9, 512) (5, 5, 5, 512)
36 : Operands could not be broadcast together with shapes (9, 9, 9, 512) (5, 5, 5, 512)
37 : Operands could not be broadcast together with shapes (5, 5, 5, 1024) (3, 3, 3, 1024)
38 : Operands could not be broadcast together with shapes (5, 5, 5, 1024) (3, 3, 3, 1024)
39 : Operands could not be broadcast together with shapes (5, 5, 5, 1024) (3, 3, 3, 1024)
40 : Operands could not be broadcast together with shapes (5, 5, 5, 1024) (3, 3, 3, 1024)
41 : Operands could not be broadcast together with shapes (11, 11, 11, 512) (6, 6, 6, 512)
42 : Operands could not be broadcast together with shapes (11, 11, 11, 512) (6, 6, 6, 512)
43 : Operands could not be broadcast together with shapes (11, 11, 11, 512) (6, 6, 6, 512)
44 : Operands could not be broadcast together with shapes (11, 11, 11, 512) (6, 6, 6, 512)
45 : Operands could not be broadcast together with shapes (3, 3, 3, 2048) (2, 2, 2, 2048)
46 : Operands could not be broadcast together with shapes (3, 3, 3, 2048) (2, 2, 2, 2048)
47 : Operands could not be broadcast together with shapes (3, 3, 3, 2048) (2, 2, 2, 2048)
48 : Operands could not be broadcast together with shapes (3, 3, 3, 2048) (2, 2, 2, 2048)
49 : Operands could not be broadcast together with shapes (13, 13, 13, 512) (7, 7, 7, 512)
50 : Operands could not be broadcast together with shapes (13, 13, 13, 512) (7, 7, 7, 512)
51 : Operands could not be broadcast together with shapes (13, 13, 13, 512) (7, 7, 7, 512)
52 : Operands could not be broadcast together with shapes (13, 13, 13, 512) (7, 7, 7, 512)
53 : Operands could not be broadcast together with shapes (7, 7, 7, 1024) (4, 4, 4, 1024)
54 : Operands could not be broadcast together with shapes (7, 7, 7, 1024) (4, 4, 4, 1024)
55 : Operands could not be broadcast together with shapes (7, 7, 7, 1024) (4, 4, 4, 1024)
56 : Operands could not be broadcast together with shapes (7, 7, 7, 1024) (4, 4, 4, 1024)
57 : Operands could not be broadcast together with shapes (15, 15, 15, 512) (8, 8, 8, 512)
58 : Operands could not be broadcast together with shapes (15, 15, 15, 512) (8, 8, 8, 512)
59 : Operands could not be broadcast together with shapes (15, 15, 15, 512) (8, 8, 8, 512)
60 : Operands could not be broadcast together with shapes (15, 15, 15, 512) (8, 8, 8, 512)
61 : ok
62 : ok
63 : ok
64 : ok
65 : Operands could not be broadcast together with shapes (17, 17, 17, 512) (9, 9, 9, 512)
66 : Operands could not be broadcast together with shapes (17, 17, 17, 512) (9, 9, 9, 512)
67 : Operands could not be broadcast together with shapes (17, 17, 17, 512) (9, 9, 9, 512)
68 : Operands could not be broadcast together with shapes (17, 17, 17, 512) (9, 9, 9, 512)
69 : Operands could not be broadcast together with shapes (9, 9, 9, 1024) (5, 5, 5, 1024)
70 : Operands could not be broadcast together with shapes (9, 9, 9, 1024) (5, 5, 5, 1024)
71 : Operands could not be broadcast together with shapes (9, 9, 9, 1024) (5, 5, 5, 1024)
72 : Operands could not be broadcast together with shapes (9, 9, 9, 1024) (5, 5, 5, 1024)
73 : Operands could not be broadcast together with shapes (19, 19, 19, 512) (10, 10, 10, 512)
74 : Operands could not be broadcast together with shapes (19, 19, 19, 512) (10, 10, 10, 512)
75 : Operands could not be broadcast together with shapes (19, 19, 19, 512) (10, 10, 10, 512)
76 : Operands could not be broadcast together with shapes (19, 19, 19, 512) (10, 10, 10, 512)
77 : Operands could not be broadcast together with shapes (5, 5, 5, 2048) (3, 3, 3, 2048)
78 : Operands could not be broadcast together with shapes (5, 5, 5, 2048) (3, 3, 3, 2048)
79 : Operands could not be broadcast together with shapes (5, 5, 5, 2048) (3, 3, 3, 2048)
80 : Operands could not be broadcast together with shapes (5, 5, 5, 2048) (3, 3, 3, 2048)
81 : Operands could not be broadcast together with shapes (21, 21, 21, 512) (11, 11, 11, 512)
82 : Operands could not be broadcast together with shapes (21, 21, 21, 512) (11, 11, 11, 512)
83 : Operands could not be broadcast together with shapes (21, 21, 21, 512) (11, 11, 11, 512)
84 : Operands could not be broadcast together with shapes (21, 21, 21, 512) (11, 11, 11, 512)
85 : Operands could not be broadcast together with shapes (11, 11, 11, 1024) (6, 6, 6, 1024)
86 : Operands could not be broadcast together with shapes (11, 11, 11, 1024) (6, 6, 6, 1024)
87 : Operands could not be broadcast together with shapes (11, 11, 11, 1024) (6, 6, 6, 1024)
88 : Operands could not be broadcast together with shapes (11, 11, 11, 1024) (6, 6, 6, 1024)
89 : Operands could not be broadcast together with shapes (23, 23, 23, 512) (12, 12, 12, 512)
90 : Operands could not be broadcast together with shapes (23, 23, 23, 512) (12, 12, 12, 512)
91 : Operands could not be broadcast together with shapes (23, 23, 23, 512) (12, 12, 12, 512)
92 : Operands could not be broadcast together with shapes (23, 23, 23, 512) (12, 12, 12, 512)
93 : ok
94 : ok
95 : ok
96 : ok
97 : Operands could not be broadcast together with shapes (25, 25, 25, 512) (13, 13, 13, 512)
98 : Operands could not be broadcast together with shapes (25, 25, 25, 512) (13, 13, 13, 512)
99 : Operands could not be broadcast together with shapes (25, 25, 25, 512) (13, 13, 13, 512)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shijianjiancommented, Jan 2, 2019

Thank @mkompanek for the fix While I think use math.ceil makes more sense than add 0.5 here.

from math import ceil

stride_dim1 = ceil((input._keras_shape[DIM1_AXIS] / residual._keras_shape[DIM1_AXIS]))
stride_dim2 = ceil((input._keras_shape[DIM2_AXIS] / residual._keras_shape[DIM2_AXIS]))
stride_dim3 = ceil((input._keras_shape[DIM3_AXIS] / residual._keras_shape[DIM3_AXIS]))
2reactions
mkompanekcommented, Nov 9, 2018

Hi, I fixed the problem by changing shortcut function:

def _shortcut3d(input, residual):
    """3D shortcut to match input and residual and merges them with "sum"."""    
    stride_dim1 = int((input._keras_shape[DIM1_AXIS] / residual._keras_shape[DIM1_AXIS])+0.5)
    stride_dim2 = int((input._keras_shape[DIM2_AXIS] / residual._keras_shape[DIM2_AXIS])+0.5)
    stride_dim3 = int((input._keras_shape[DIM3_AXIS] / residual._keras_shape[DIM3_AXIS])+0.5)    
    equal_channels = residual._keras_shape[CHANNEL_AXIS] == input._keras_shape[CHANNEL_AXIS]

    shortcut = input
    if stride_dim1 > 1 or stride_dim2 > 1 or stride_dim3 > 1 \
            or not equal_channels:
        shortcut = Conv3D(
            filters=residual._keras_shape[CHANNEL_AXIS],
            kernel_size=(1, 1, 1),
            strides=(stride_dim1, stride_dim2, stride_dim3),
            kernel_initializer="he_normal", padding="valid",
            kernel_regularizer=l2(1e-4)
            )(input)
    
    return add([shortcut, residual])

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keras input explanation: input_shape, units, batch_size, ...
The input shape. What flows between layers are tensors. Tensors can be seen as matrices, with shapes. In Keras, the input layer itself...
Read more >
Input object
Input () is used to instantiate a Keras tensor. A Keras tensor is a symbolic tensor-like object, which we augment with certain attributes...
Read more >
Keras Input Shape: The Beginning Of Every Model - EML
The Keras input shape is a parameter for the input layer (InputLayer). You'll use the input shape parameter to define a tensor for...
Read more >
How to determine input shape in keras?
The number of rows in your training data is not part of the input shape of the network because the training process feeds...
Read more >
Ultimate Guide to Input shape and Model Complexity in ...
In Keras, the input dimension needs to be given excluding the batch-size (number of samples). In this neural network, the input shape is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found