def evaluate(model, dataset, crop_margin, test_size, batch_size):
xp = model.xp
iterator = chainer.iterators.SerialIterator(dataset, batch_size, repeat=False, shuffle=False)
acc_sum = 0
iteration = 0
for batch in iterator:
image_batch = []
label_batch = []
for image_path, category_id, _ in batch:
image = load_image(image_path)
image_width, image_height = image.size
crop_size = min(image_width, image_height) - crop_margin
crop_rect = ((image_width - crop_size) // 2, (image_height - crop_size) // 2, crop_size, crop_size)
input_size = test_size
image_batch.append(transform_image(image, crop_rect, input_size))
label_batch.append(category_id)
x = xp.asarray(image_batch)
t = xp.asarray(label_batch)
with chainer.using_config('enable_backprop', False):
with chainer.using_config('train', False):
y = model(x)
acc = F.accuracy(y, t)
acc_sum += float(acc.data) * batch_size
return acc_sum / len(dataset)
yolov2_train_class.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录