Using the yad2k.py script as is with the yolov2-tiny.cfg and yolov2-tiny.weights results in all nan predictions in Keras. I tracked the problem down to the fact that the batch norm layers end up with negative values for the rolling_variance parameters in the first filter position. This should never happen (variance should be >0).
I traced things through the original Darknet repo and the issue appears to be an extra read when loading the weights header. In the original Darknet code, there is an if statement that either reads the last value of the header as sizeof(int) or sizeof(int) bytes depending on the header. This works out to 8 or 4 bytes, respectively. The python code in YAD2k, however, reads 4 bytes no matter what. The most recent version of the yolov2-tiny.weights should read 8 bytes in the last spot causing an alignment issue when you try to convert things with the yad2k.py script. You can remedy the issue by changing this line to read:
Using the yad2k.py script as is with the
yolov2-tiny.cfg
andyolov2-tiny.weights
results in allnan
predictions in Keras. I tracked the problem down to the fact that the batch norm layers end up with negative values for therolling_variance
parameters in the first filter position. This should never happen (variance should be >0).I traced things through the original Darknet repo and the issue appears to be an extra read when loading the weights header. In the original Darknet code, there is an if statement that either reads the last value of the header as
sizeof(int)
orsizeof(int)
bytes depending on the header. This works out to 8 or 4 bytes, respectively. The python code in YAD2k, however, reads 4 bytes no matter what. The most recent version of theyolov2-tiny.weights
should read 8 bytes in the last spot causing an alignment issue when you try to convert things with theyad2k.py
script. You can remedy the issue by changing this line to read: