MaybeShewill-CV / lanenet-lane-detection

Unofficial implemention of lanenet model for real time lane detection
Apache License 2.0
2.35k stars 885 forks source link

error while training for multiple classes #542

Closed Neelesh-G closed 2 years ago

Neelesh-G commented 2 years ago

hello I am trying to train the network for multiclass classification(white lanes, yellow lanes and road edges etc). I have labelled the binary data accordingly(different pixels values for different classes) and have increased the num_classes in the config file to 3. But I am getting the below error


tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.
  (0) Invalid argument: Incompatible shapes: [1,256,512,3] vs. [2]
     [[node tower_1/LaneNet/bisenetv2_backend/binary_seg/Mul (defined at /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/ops.py:1748) ]]
     [[tower_0/gradients/Add/_114]]
  (1) Invalid argument: Incompatible shapes: [1,256,512,3] vs. [2]
     [[node tower_1/LaneNet/bisenetv2_backend/binary_seg/Mul (defined at /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/ops.py:1748) ]]
0 successful operations.
0 derived errors ignored.

Original stack trace for 'tower_1/LaneNet/bisenetv2_backend/binary_seg/Mul':
  File "train_lanenet_tusimple.py", line 40, in <module>
    train_model()
  File "train_lanenet_tusimple.py", line 27, in train_model
    worker = multi_gpu_trainner.LaneNetTusimpleMultiTrainer(cfg=CFG)
  File "/content/drive/MyDrive/lane_detection/lanenet-lane-detection-master/tools/trainner/tusimple_lanenet_multi_gpu_trainner.py", line 157, in __init__
    is_net_first_initialized=is_network_initialized
  File "/content/drive/MyDrive/lane_detection/lanenet-lane-detection-master/tools/trainner/tusimple_lanenet_multi_gpu_trainner.py", line 354, in _compute_net_gradients
    reuse=is_net_first_initialized
  File "/content/drive/MyDrive/lane_detection/lanenet-lane-detection-master/tools/lanenet_model/lanenet.py", line 85, in compute_loss
    reuse=reuse
  File "/content/drive/MyDrive/lane_detection/lanenet-lane-detection-master/tools/lanenet_model/lanenet_back_end.py", line 145, in compute_loss
    classes_weights=inverse_weights
  File "/content/drive/MyDrive/lane_detection/lanenet-lane-detection-master/tools/lanenet_model/lanenet_back_end.py", line 56, in _compute_class_weighted_cross_entropy_loss
    loss_weights = tf.reduce_sum(tf.multiply(onehot_labels, classes_weights), axis=3)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/util/dispatch.py", line 180, in wrapper
    return target(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/ops/math_ops.py", line 331, in multiply
    return gen_math_ops.mul(x, y, name)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/ops/gen_math_ops.py", line 6701, in mul
    "Mul", x=x, y=y, name=name)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op
    attrs, op_def, compute_device)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal
    op_def=op_def)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/ops.py", line 1748, in __init__
    self._traceback = tf_stack.extract_stack()_

will the tf.unique_with_counts() take care of the number of classes or do I have to do anything extra?

MaybeShewill-CV commented 2 years ago

@Neelesh-G Error occured in binary segmentation branch. You may try to train the model without class weights. Check here https://github.com/MaybeShewill-CV/lanenet-lane-detection/blob/94be8d9a66c7bbda5ad99b10492bc406c8aee45f/lanenet_model/lanenet_back_end.py#L123-L128

pankaj251003 commented 2 years ago

@Neelesh-G Have yo solved the errro...if yes please let me know how?

Neelesh-G commented 1 year ago

No, I have not gotten the time to solve it yet. If you are successful, please let me know.

On Sun, 25 Sept 2022 at 01:25, pankaj251003 @.***> wrote:

@Neelesh-G https://github.com/Neelesh-G Have yo solved the errro...if yes please let me know how?

— Reply to this email directly, view it on GitHub https://github.com/MaybeShewill-CV/lanenet-lane-detection/issues/542#issuecomment-1257123668, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARIYNLA6TGOKA4RFE7GP67LV77O37ANCNFSM5PQJNDJA . You are receiving this because you were mentioned.Message ID: @.***>