Let’s change the Makefile to use the CPU more effectively.

# https://stackoverflow.com/questions/39086/search-and-replace-a-line-in-a-file-in-python

f = open(DN + '/Makefile', 'r')
lines = ''
for line in f:
#    if line.find('GPU=0') != -1:
#        line = line.replace('GPU=0', 'GPU=1')
#    if line.find('CUDNN=0') != -1:
#       line = line.replace('CUDNN=0', 'CUDNN=1')
#    if line.find('CUDNN_HALF=0') != -1:
#       line = line.replace('CUDNN_HALF=0', 'CUDNN_HALF=1')
    if line.find('OPENCV=0') != -1:
        line = line.replace('OPENCV=0', 'OPENCV=1')
    if line.find('AVX=0') != -1:
        line = line.replace('AVX=0', 'AVX=1')
    if line.find('OPENMP=0') != -1:
        line = line.replace('OPENMP=0', 'OPENMP=1')
    lines += line
f.close()

g = open('/content/darknet/Makefile', 'w')
g.write(lines)
g.close()

It’s certainly faster and should also be used with the GPU so let’s bring it together.

# https://stackoverflow.com/questions/39086/search-and-replace-a-line-in-a-file-in-python

f = open(DN + '/Makefile', 'r')
lines = ''
for line in f:
    if line.find('GPU=0') != -1:
        line = line.replace('GPU=0', 'GPU=1')
    if line.find('CUDNN=0') != -1:
       line = line.replace('CUDNN=0', 'CUDNN=1')
    if line.find('CUDNN_HALF=0') != -1:
       line = line.replace('CUDNN_HALF=0', 'CUDNN_HALF=1')
    if line.find('OPENCV=0') != -1:
        line = line.replace('OPENCV=0', 'OPENCV=1')
    if line.find('AVX=0') != -1:
        line = line.replace('AVX=0', 'AVX=1')
    if line.find('OPENMP=0') != -1:
        line = line.replace('OPENMP=0', 'OPENMP=1')
    lines += line
f.close()

g = open('/content/darknet/Makefile', 'w')
g.write(lines)
g.close()

Now we should have everything working. This, of course, assumes that there is a GPU available, a requirement that Google Colab can meet.