【tqdm】终端输出进度

代码使用:

from tqdm import tqdm
import sys

#Testing
def test(model, testLoader, topk=(1,)):
    model.eval()
	# 只是多了下面这一行
    testLoader = tqdm(testLoader, file=sys.stdout)
    with torch.no_grad():
        for batch_idx, (inputs, targets) in enumerate(testLoader):
            inputs, targets = inputs.to(device), targets.to(device)
            outputs = model(inputs)
            loss = loss_func(outputs, targets)
            ...

输出:

  4%|████                     | 8/196 [00:10<03:25,  1.09s/it]

猜你喜欢

转载自blog.csdn.net/weixin_45377629/article/details/126605218