当前位置: 七九推 > IT编程>数据库>Access > NotImplementedError: Got <class ‘__main__.AverageMeter‘>, but expected numpy array or torch tensor

NotImplementedError: Got <class ‘__main__.AverageMeter‘>, but expected numpy array or torch tensor

2022年06月23日 Access 我要评论
问题 File "main_finetune_pointConv_torchModel.py", line 484, in <module> main() Fi

问题

  File "main_finetune_pointConv_torchModel.py", line 484, in <module>
    main()
  File "main_finetune_pointConv_torchModel.py", line 296, in main
    train(train_loader, model, criterion, optimizer, epoch)
  File "main_finetune_pointConv_torchModel.py", line 371, in train
    writer.add_scalar('train/loss_epoch', losses, epoch)
  File "/home/SSD/roth/myProjectEnv/rethinking-network-pruning-conda-py3.6/lib/python3.6/site-packages/tensorboardX/writer.py", line 405, in add_scalar
    scalar(tag, scalar_value), global_step, walltime)
  File "/home/SSD/roth/myProjectEnv/rethinking-network-pruning-conda-py3.6/lib/python3.6/site-packages/tensorboardX/summary.py", line 146, in scalar
    scalar = make_np(scalar)
  File "/home/SSD/roth/myProjectEnv/rethinking-network-pruning-conda-py3.6/lib/python3.6/site-packages/tensorboardX/x2num.py", line 34, in make_np
    'Got {}, but expected numpy array or torch tensor.'.format(type(x)))
NotImplementedError: Got <class '__main__.AverageMeter'>, but expected numpy array or torch tensor.


代码

def train(train_loader, model, criterion, optimizer, epoch):
    batch_time = AverageMeter()
    data_time = AverageMeter()
    losses = AverageMeter()
    top1 = AverageMeter()
    top5 = AverageMeter()

    # switch to train mode
    model.train()

    end = time.time()
    for i, (input, target) in enumerate(train_loader):
        # measure data loading time
        data_time.update(time.time() - end)

        # target = target.cuda(async=True)
        target = target.cuda(non_blocking=True)            # python 3.7x
        input_var = torch.autograd.Variable(input)
        target_var = torch.autograd.Variable(target)

        # compute output
        output = model(input_var)
        loss = criterion(output, target_var)

        # measure accuracy and record loss
        prec1, prec5 = accuracy(output.data, target, topk=(1, 5))
        losses.update(loss.item(), input.size(0))
        top1.update(prec1[0], input.size(0))
        top5.update(prec5[0], input.size(0))

        # compute gradient and do SGD step
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

        # measure elapsed time
        batch_time.update(time.time() - end)
        end = time.time()


        if i % args.print_freq == 0:
            print('Epoch: [{0}][{1}/{2}]\t'
                  'Time {batch_time.val:.3f} ({batch_time.avg:.3f})\t'
                  'Data {data_time.val:.3f} ({data_time.avg:.3f})\t'
                  'Loss {loss.val:.4f} ({loss.avg:.4f})\t'
                  'Prec@1 {top1.val:.3f} ({top1.avg:.3f})\t'
                  'Prec@5 {top5.val:.3f} ({top5.avg:.3f})'.format(
                   epoch, i, len(train_loader), batch_time=batch_time,
                   data_time=data_time, loss=losses, top1=top1, top5=top5))

    writer.add_scalar('train/loss_epoch', losses, epoch)  # ---------这里报错--------
    writer.add_scalar('train/top1_epoch', top1, epoch)
    writer.add_scalar('train/top5_epoch', top5, epoch)

解决:


writer.add_scalar('train/loss_epoch', losses.avg, epoch)
writer.add_scalar('train/top1_epoch', top1.avg, epoch)
writer.add_scalar('train/top5_epoch', top5.avg, epoch)

(0)
打赏 微信扫一扫 微信扫一扫

相关文章:

  • 鼎捷T100标准接口调用

    鼎捷T100标准接口调用

    一、接口信息 我们先找接口信息,它们正常情况下都存在azzi700集成服务基本数据维护作业内, 接口地址:http:... [阅读全文]
  • (已解决)xxx.jar包中没有主清单属性

    (已解决)xxx.jar包中没有主清单属性

    通过IDEA打的程序包,在运行的时候,提示没有主清单属性,也就是说找不到启动类  当前问题解决答案更新一版࿰... [阅读全文]
  • RandomAccessFile简介

    RandomAccessFile简介

    RandomAccessFile 功能构造函数特殊方法 功能 想比较之前的流要么读要么写,RandomAccessFile提供了读写操作Rando... [阅读全文]
  • 
    Apache的日志access_log分析

    Apache的日志access_log分析

    正常日志格式:客户端地址 访问者的标识 访问者的验证名字 请求的时间 请求类型 请求的http代码 发送给客户端的字节数 当网站出问题时分析日志,第一步一般都不... [阅读全文]
  • insertBefore的用法

    insertBefore的用法

    文章目录 简介用法参数 注意的地方 简介 inserBefore,顾名思义就知道是“在某个节点之前插入”。而MDN文档的说法是: ... [阅读全文]
  • 计算机丢失lua51dll怎么修复,lua51.dll

    计算机丢失lua51dll怎么修复,lua51.dll

    lua源文件--obfuscate-->lua源文件(混淆后)--compile-->luac文件(带调试用的变量名和行号)--strip-->... [阅读全文]

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2022  七九推 保留所有权利. 粤ICP备17035492号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com