本文整理匯總了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)