本文整理汇总了Python中test.Test方法的典型用法代码示例。如果您正苦于以下问题:Python test.Test方法的具体用法?Python test.Test怎么用?Python test.Test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test
的用法示例。
在下文中一共展示了test.Test方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: import test [as 别名]
# 或者: from test import Test [as 别名]
def test(model, test_loader, class_weights, class_encoding):
print("\nTesting...\n")
num_classes = len(class_encoding)
# We are going to use the CrossEntropyLoss loss function as it's most
# frequentely used in classification problems with multiple classes which
# fits the problem. This criterion combines LogSoftMax and NLLLoss.
criterion = nn.CrossEntropyLoss(weight=class_weights)
# Evaluation metric
if args.ignore_unlabeled:
ignore_index = list(class_encoding).index('unlabeled')
else:
ignore_index = None
metric = IoU(num_classes, ignore_index=ignore_index)
# Test the trained model on the test set
test = Test(model, test_loader, criterion, metric, device)
print(">>>> Running test dataset")
loss, (iou, miou) = test.run_epoch(args.print_step)
class_iou = dict(zip(class_encoding.keys(), iou))
print(">>>> Avg. loss: {0:.4f} | Mean IoU: {1:.4f}".format(loss, miou))
# Print per class IoU
for key, class_iou in zip(class_encoding.keys(), iou):
print("{0}: {1:.4f}".format(key, class_iou))
# Show a batch of samples and labels
if args.imshow_batch:
print("A batch of predictions from the test set...")
images, _ = iter(test_loader).next()
predict(model, images, class_encoding)
示例2: test
# 需要导入模块: import test [as 别名]
# 或者: from test import Test [as 别名]
def test(model, test_loader, class_weights, class_encoding, step):
print("\nTesting...\n")
num_classes = len(class_encoding)
# We are going to use the CrossEntropyLoss loss function as it's most
# frequentely used in classification problems with multiple classes which
# fits the problem. This criterion combines LogSoftMax and NLLLoss.
criterion = nn.CrossEntropyLoss(weight=class_weights)
if use_cuda:
criterion = criterion.cuda()
# Evaluation metric
if args.ignore_unlabeled:
ignore_index = list(class_encoding).index('unlabeled')
else:
ignore_index = None
metric = IoU(num_classes, ignore_index=ignore_index)
# Test the trained model on the test set
test = Test(model, test_loader, criterion, metric, use_cuda, step)
print(">>>> Running test dataset")
loss, (iou, miou) = test.run_epoch(args.print_step)
class_iou = dict(zip(class_encoding.keys(), iou))
print(">>>> Avg. loss: {0:.4f} | Mean IoU: {1:.4f}".format(loss, miou))
# Print per class IoU
for key, class_iou in zip(class_encoding.keys(), iou):
print("{0}: {1:.4f}".format(key, class_iou))
# Show a batch of samples and labels
if args.imshow_batch:
print("A batch of predictions from the test set...")
images, _ = iter(test_loader).next()
predict(model, images, class_encoding)
示例3: invoke
# 需要导入模块: import test [as 别名]
# 或者: from test import Test [as 别名]
def invoke(self, object, args):
obj = _cast(object, lambda: test.Test);
(obj).go();
return None
示例4: __init__
# 需要导入模块: import test [as 别名]
# 或者: from test import Test [as 别名]
def __init__(self):
super(test_Test, self).__init__(u"test.Test");
(self).name = u"test.Test"
(self).parameters = _List([])
(self).fields = _List([quark.reflect.Field(u"quark.String", u"name")])
(self).methods = _List([test_Test_go_Method()])
(self).parents = _List([u"quark.Object"])
示例5: construct
# 需要导入模块: import test [as 别名]
# 或者: from test import Test [as 别名]
def construct(self, args):
return test.Test()
示例6: main
# 需要导入模块: import test [as 别名]
# 或者: from test import Test [as 别名]
def main(config):
from torch.backends import cudnn
# For fast training
cudnn.benchmark = True
data_loader = get_loader(
config.mode_data,
config.image_size,
config.batch_size,
config.dataset_fake,
config.mode,
num_workers=config.num_workers,
all_attr=config.ALL_ATTR,
c_dim=config.c_dim)
from misc.scores import set_score
if set_score(config):
return
if config.mode == 'train':
from train import Train
Train(config, data_loader)
from test import Test
test = Test(config, data_loader)
test(dataset=config.dataset_real)
elif config.mode == 'test':
from test import Test
test = Test(config, data_loader)
if config.DEMO_PATH:
test.DEMO(config.DEMO_PATH)
else:
test(dataset=config.dataset_real)