Closed huaiyanggongzi closed 7 years ago
Hi, do you use tensorflow as a backend ? With theano the code works fine. It seems strange, and i can't remember the reason why the code looks like this. Maybe the reason - opencv, different versions.
Hi Edward,
I am using tensorflow as a backend.
As a temporary walkaround, I just set cols=rows. to bypass this issue. However, I still have difficulties to get the code run. Generally, the thing I changed is to ensure the image is of shape (batch, width, height, 1).
In your code, I did not find other places which are Theano dependent. Do you have any suggestions for which part of the code I may need to modify to make it Tensorflow runnable. Thanks.
Huaiyang
augmentation.py contains theano-dep code (CustomImageDataGenerator) is case you run train_generator.py
It's odd, I used tf backend without a problem (
Hi Edward,
Originally, I changed the image shape to (nb_sample, height, width, 1) to comply with TF. It gave me the error message as mentioned above. I just changed it back to (nb_sample, 1, height, width), and still use Tensorflow as backend. Now it can run. But frankly speaking, I am not sure why that can solve the problem. Does that mean we should always use Theano way to represent the image shape regardless the backend.
Thanks a lot.
Huaiyang
Hi. I don't know every aspect of the keras switching between backends. But almost every keras module has a dim_ordering parameter, which can easily be modified in the keras config.
For example, in my environment I've created a file - ~/.keras/keras.json with the following content:
{ "image_dim_ordering": "th", "epsilon": 1e-07, "floatx": "float32", "backend": "theano" }
You can substitute backend to "tensorflow" and keep image_dim_ordering as "th".
More information here
Thank you very much for the help! Happy New Year!
Hi Edward,
While running your code, I have a question regarding
preprocess(imgs)
.At first, you define imgs_p with the shape of
(batchsize, channel, to_rows,to_cols)
. However, in the resize function, you resize the original image to(to_cols, to_rows)
. It seems to me that it should resize to(to_rows,to_cols)
.In fact, if I use the original shape,
imgs_p[i, 0] = resize(imgs[i, 0], (to_cols, to_rows))
I got the following error messageTraceback (most recent call last): File "train.py", line 153, in <module> train_and_predict() File "train.py", line 92, in train_and_predict imgs_train = preprocess(imgs_train) File "train.py", line 81, in preprocess imgs_p[i, 0] = resize(imgs[i, 0], (to_cols, to_rows)) ValueError: could not broadcast input array from shape (80,64) into shape (64,80)
Would you like to take a look at this issue? Thank you very much.