Does object detection support focal loss?
If yes, how to enable it in the object detection configuration?
Thanks,
@kaishijeng Its experimental. You could change the classification loss in the config to something like
classification_loss {
weighted_sigmoid_focal {
anchorwise_output: true
gamma: 2.0
alpha: 0.75
}
}
and removing the hard example mining section from the config.
I follow your instruction and got the following error:
File "object_detection/train.py", line 198, in
I check out the latest models and now is OK to run it. However, I encounter an error below:
2017-11-01 21:26:04.115929: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: exceptions.TypeError: 'numpy.float64' object cannot be interpreted as an index INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.UnknownError'>, exceptions.RuntimeError: main thread is not in main loop [[Node: Loss/PyFunc = PyFuncTin=[DT_FLOAT], Tout=[DT_UINT8], token="pyfunc_0", _device="/job:localhost/replica:0/task:0/device:CPU:0"]]
Caused by op u'Loss/PyFunc', defined at:
File "object_detection/train.py", line 163, in
Here is my configuration: classification_loss { weighted_sigmoid_focal { anchorwise_output: true gamma: 2.0 alpha: 0.75 } } localization_loss { weighted_smooth_l1 { anchorwise_output: true } }
If I use a regular loss as below, training is running OK classification_loss { weighted_sigmoid { anchorwise_output: true } } localization_loss { weighted_smooth_l1 { anchorwise_output: true } } hard_example_miner { num_hard_examples: 3000 iou_threshold: 0.99 loss_type: CLASSIFICATION max_negatives_per_positive: 3 min_negatives_per_image: 0 }
@tombstone
Can you reopen this issue until it resolves?
Thanks,
I just commented the line 482 and 483 in the object_detection/meta_architectures/ssd_meta_arch.py. Then the training is working again.
I think this error is caused by some new features added recently. The error log shows in the object_detection/utils/visualization_utils.py, cdf_plot tries to compute float64 values and return an uint8 image, but the tf.py_func somehow cannot pass Tin=[DT_FLOAT] to Tout=[DT_UINT8].
@tombstone can you help check this py_func?
@izzrak
It works. Will this get fixed in the github? By the way, what are good values to use for Gamma/Alpha?
Thanks,
@kaishijeng I tried my first training result on some test images and it looks very bad. Since the new evaluator is broken as well, I need do some test to make sure the focal loss is working as intended. The paper claims that they got the best result when gamma = 2 and alpha = 0.25, you can definitely start with this pair.
@izzrak You may want to check Lilian's implementation of local loss in Tensorflow below. https://github.com/lijiancheng0614/tensorflow_object_detection
Not sure correctness of his focal loss implementation
I just updated to the latest commit, looks like they fixed the training issue. I tried the focal loss they provided and it worked great. The converge speed of the precision is faster and the loss is much smaller.
@izzrak
I just updated to the latest commit Should I just check out the latest models to get your latest commit? Thanks,