コード例 #1
0
    expected_classid = 1  # Only tigers
elif 'elp' in folder.lower() or 'elephant' in folder.lower():
    expected_classid = 2
elif 'amur' in folder.lower():
    expected_classid = 3

mAP = 0.
numBoxes = 0
wrong = 0
correct = 0
start = time.time()
for i in range(0, n, batchSize):
    m = min(n, i + batchSize)
    images = [cv2.imread(imageFiles[x]) for x in range(i, m)]

    results = det.getBatchDetectionResults(images)
    for j in range(i, m):  # For each image in batch
        imageIndex = os.path.basename(imageFiles[j]).split('.')[0]
        ground_truth = box_map[imageIndex]
        result = results[j - i]
        if not len(result) == len(ground_truth):
            print(
                'Incorrect number of detections for image {}, Actual: {}, Expected: {}'
                .format(imageFiles[j], len(result), len(ground_truth)))
        for res in result:
            if not res.classid == expected_classid:
                print(
                    'Incorrect classification for {}, Actual class id: {}, Expected: {}'
                    .format(imageFiles[j], res.classid, expected_classid))
                wrong += 1
            else:
コード例 #2
0
det.getBoundingBoxes(img)
det.getBoundingBoxes(img)

batchTimes = []
lower = 10
upper = 11

if len(args) == 4:
    lower = int(args[2])
    upper = int(args[3])

f = open('test_times.csv', 'w')
f.write('Batch Size,Total Time,Average Time\n')
for i in range(lower, upper, 5):
    batchSize = i
    # Detect batchSize images at a time
    cur = 0
    print('Running inference {} images at a time ...'.format(batchSize))
    start = time.time()
    while cur < n:
        images = imageFiles[cur:min(n, cur + batchSize)]
        cur += batchSize
        det.getBatchDetectionResults([cv2.imread(x) for x in images])
    total = time.time() - start
    print('Total detection time for batchSize {}: {:.2f}s, Average: {:.2f}s'.
          format(i, total, total / n))
    f.write('{},{},{}\n'.format(i, total, total / n))

print('Completed...')
f.close()