jakeret / tf_unet

Generic U-Net Tensorflow implementation for image segmentation
GNU General Public License v3.0
1.9k stars 748 forks source link

ValueError: could not broadcast input array from shape #213

Closed stiv-yakovenko closed 5 years ago

stiv-yakovenko commented 6 years ago

This code:

from tf_unet import unet, util, image_util
data_provider = image_util.ImageDataProvider("./images_and_labels/*.tif")
net = unet.Unet(layers=3, features_root=64, channels=1, n_class=2)
trainer = unet.Trainer(net)
path = trainer.train(data_provider, "./model_unet", training_iters=32, epochs=100)

on folder:

image

gives this crash:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1664, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/steve/Project/solarpanels/train_unet.py", line 9, in <module>
    path = trainer.train(data_provider, "./model_unet", training_iters=32, epochs=100)
  File "C:\Users\steve\AppData\Roaming\Python\Python36\site-packages\tf_unet-0.1.1-py3.6.egg\tf_unet\unet.py", line 422, in train
    test_x, test_y = data_provider(self.verification_batch_size)
  File "C:\Users\steve\AppData\Roaming\Python\Python36\site-packages\tf_unet-0.1.1-py3.6.egg\tf_unet\image_util.py", line 98, in __call__
    X[i] = train_data
ValueError: could not broadcast input array from shape (470,773,1) into shape (470,772,1)

any ideas why?

stiv-yakovenko commented 6 years ago

After resizing images to the same shape i get this error:

Traceback (most recent call last):
  File "C:\Users\steve\Miniconda3\lib\site-packages\tensorflow\python\client\session.py", line 1322, in _do_call
    return fn(*args)
  File "C:\Users\steve\Miniconda3\lib\site-packages\tensorflow\python\client\session.py", line 1307, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "C:\Users\steve\Miniconda3\lib\site-packages\tensorflow\python\client\session.py", line 1409, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be broadcastable: logits_size=[1234688,2] labels_size=[1239300,2]
     [[Node: cost/softmax_cross_entropy_with_logits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](cost/softmax_cross_entropy_with_logits/Reshape, cost/softmax_cross_entropy_with_logits/Reshape_1)]]
stiv-yakovenko commented 6 years ago

It looks like input images should be rectangle. Is that critical?

Toy problem with these params fails:

nx = 467
ny = 679
generator = GrayScaleDataProvider(nx, ny, cnt=20)
jakeret commented 6 years ago

There is a known bug if nx and ny is not even. I'm not aware that something doesn't work if nx!=ny

jakeret commented 5 years ago

fixed