部署U-net过程中遇到的问题

这篇具有很好参考价值的文章主要介绍了部署U-net过程中遇到的问题。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、问题1:AttributeError: module ‘wandb’ has no attribute ‘init’

在pycharm中打开U-net的代码包,运行报错:AttributeError: module ‘wandb’ has no attribute ‘init’

解决办法:因为运行环境是conda pycharm01
attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch
首先激活环境,然后安装wandb
pip3 install wandb
attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch

二、问题2: requests.exceptions.ProxyError: HTTPSConnectionPool(host=‘api.wandb.ai’, port=443): Max retries exceeded with url: /graphql (Caused by ProxyError(‘Cannot connect to proxy.’, OSError(0, ‘Error’)))

然后遇到第二个问题:
之前查错挂了梯子,然后我把梯子退出,问题解决。

三、问题3: torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 80.00 MiB

问题3:

input, weight, bias, running_mean, running_var, training, momentum, eps, torch.backends.cudnn.enabled
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 80.00 MiB (GPU 0; 2.00 GiB total capacity; 1.59 GiB already allocated; 0 bytes free; 1.68 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
wandb: Waiting for W&B process to finish... (failed 1). Press Ctrl-C to abort syncing.
wandb: ERROR Failed to serialize metric: division by zero
wandb: Synced curious-puddle-1: https://wandb.ai/anony-moose-445420/U-Net/runs/2o8l71a4?apiKey=269d1610694140326baeb759b57d6483f8c2db9d
wandb: Synced 5 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)
wandb: Find logs at: .\wandb\run-20221120_180900-2o8l71a4\logs

解决办法:
将batch_size改小,(原来是5)
attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch

参考博客:https://blog.csdn.net/m0_64531459/article/details/127487627

至此,U-net成功运行。接下来是利用训练的模型进行测试

attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch

四、问题4: No module named ‘matplotlib’

在训练完成后,要测试一下训练结果
在README中看到
attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch
于是在命令行中输入,报错:No module named ‘matplotlib’

Traceback (most recent call last):
  File "predict.py", line 13, in <module>
    from utils.utils import plot_img_and_mask
  File "F:\pytorch_project\Pytorch-UNet-master1\utils\utils.py", line 1, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

解决1:输入:pip install matplotlib(没有成功)

报错:

(pytorch01) F:\pytorch_project\Pytorch-UNet-master1>pip install matplotlib
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError(0, 'Error'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError(0, 'Error'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError(0, 'Error'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError(0, 'Error'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError(0, 'Error'))': /simple/matplotlib/
ERROR: Could not find a version that satisfies the requirement matplotlib (from versions: none)
ERROR: No matching distribution found for matplotlib

解决2:输入 pip install matplotlib -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

结果:
attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch
参考:https://blog.csdn.net/qq_32651245/article/details/126166568

五、问题5:No such file or directory: ‘checkpoints/checkpoint_epoch40.pth’

解决问题4后,再次运行命令行命令:报错

(pytorch01) F:\pytorch_project\Pytorch-UNet-master1>python predict.py -i image.tif -o output.jpg
Traceback (most recent call last):
  File "predict.py", line 92, in <module>
    net.load_state_dict(torch.load(args.model, map_location=device))
  File "C:\Users\zhw\.conda\envs\pytorch01\lib\site-packages\torch\serialization.py", line 771, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "C:\Users\zhw\.conda\envs\pytorch01\lib\site-packages\torch\serialization.py", line 270, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "C:\Users\zhw\.conda\envs\pytorch01\lib\site-packages\torch\serialization.py", line 251, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'checkpoints/checkpoint_epoch40.pth'

解决办法1:

attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch
将40改为30
一共只有30个照片,这里不太清楚,明天问一下同学。

解决方法2: epochs是训练轮数的意思,在train.py代码里,原来的轮数为30,所以只会生成30个文件,所以找不到No such file or directory: ‘checkpoints/checkpoint_epoch40.pth’

所以可以修改代码train.py代码epochs=40 (原来的值为30)

 try:
        train_net(net=net,
                  epochs=40,
                  batch_size=3,  # args.batch_size,e
                  learning_rate=args.lr,
                  device=device,
                  img_scale=args.scale,
                  val_percent=args.val / 100,
                  amp=args.amp)
        torch.save(net.state_dict(), 'MODEL.pth')

再次训练模型:可以发现这次文件夹checkpoints中出现了checkpoint_epoch40.pth,
attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch

保持predict.py中的代码不变,把第50行的代码改回去即:

    parser.add_argument('--model', '-m', default='checkpoints/checkpoint_epoch40.pth', metavar='FILE',       #***shuchudijilun

运行:python predict.py -i test02.tif -o test02_out.jpg
得到结果:
attributeerror: module 'wandb' has no attribute 'init,Unet,深度学习,python,pytorch
至此,U-net网络部署完成!文章来源地址https://www.toymoban.com/news/detail-624280.html

到了这里,关于部署U-net过程中遇到的问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 关于 【AttributeError: module ‘collections‘ has no attribute ‘Mapping‘】出现的问题

           这个错误通常是由于在Python 3.9或更高版本中,从以上图片中看到的版本是Python3.11,`collections.Mapping`被删除所致。如果使用的是旧版本的代码,可能会导致此错误。解决此问题的方法是将代码中的`Mapping`替换为`abc.Mapping`。 例如,将以下代码:   替换为: 这将导入`

    2024年02月11日
    浏览(35)
  • 解决 AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘ 等类似的问题

    使用tensorflow2.x版本的时候,使用调用tensorflow1.x函数的代码时,常常会出现module ‘tensorflow’ has no attribute ‘contrib’这样的问题,这是由于tensorflow2.x废弃了很多tensorflow1.x API接口,本文针对常见的几种错误来使tf2.0不降版本也能运行代码。 1、报错AttributeError: module ‘tensorflow’

    2024年02月02日
    浏览(33)
  • AttributeError: module ‘torch.nn‘ has no attribute ‘SiLU‘问题的解决办法

    AttributeError: module \\\'torch.nn\\\' has no attribute \\\'SiLU\\\'        这个问题的原因是这个版本的torch中的torch.nn函数表里面没有这个SiLU函数,需要更高版本的torch,在官方的文档中我们就可以查看这个版本里有没有包含这个模块。 官方文档1.1.0    红框选择 torch 版本,我的版本是1.1.0,搜

    2024年02月13日
    浏览(41)
  • 解决 AttributeError: module ‘numpy‘ has no attribute ‘int‘ 训练yolo时的问题

    在运行yolov5的train.py出现这个报错结果。 看其他博主说的是因为库版本不对应,需要更换python或numpy版本; 原因:numpy.int在NumPy 1.20中已弃用,在NumPy 1.24中已删除。 解决方式:将numpy.int更改为numpy.int_,int。 本人一开始试了上述方法,报出了别的错,继续修改,又返回了这个

    2024年02月11日
    浏览(29)
  • 【AI 问题集】AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘

    目录 1、问题展示 2.问题原因 3.问题解决方案 4、修改代码如下 4.1 修改前 4.2修改后 5、代码执行结果 从问题中可以看到 :module  是设置成 backend_interagg 即 backend  是 agg  从源码中,我们可以看到,matplotlib.pylot 的默认 backend 是设置成agg的 源码 修改backend 方案,由于是通过 ma

    2024年04月13日
    浏览(41)
  • PyCharm中解决Matplotlib绘图时AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘问题

    问题描述: 利用PyCharm中Matplotlib绘图时,出现AttributeError: module ‘backend_interagg’ has no attribute \\\'FigureCanvas’错误。 问题原因及解决方法: matplotlib版本过高,需要降低matplotlib版本。 注:现有matplotlib版本为3.6.0,将其降低为3.5.0 至此,问题得以解决!

    2024年02月06日
    浏览(36)
  • 解决paddle.fluid与python版本不匹配的问题:AttributeError: module ‘paddle.fluid‘ has no attribute ‘xxx‘

    今天跑paddle里的代码,发现paddle里可以跑,但放到pycharm下面跑不了了,捣鼓了一下午,原来是包版本的问题,希望能对读者有一点点用。 我原本所用的环境是python3.11,它的paddlepaddle包的版本是2.5,然后我去paddle官网上看我要用的代码的配置环境(我在官网上可以跑通),打

    2024年02月03日
    浏览(32)
  • U-Net网络

    U-Net 融合了 编码 - 解码结构和跳跃网络 的特点,在模型结构上更加巧妙,主要体现在以下两点: ● ( 1 ) U-Net 模型是一个 编码 - 解码的结构 ,压缩通道是一个编码器,用于逐层提取影像的特征,扩展通道是一个解码器,用于还原影像的位置信息,且 U-Net 模型的每一个隐

    2024年02月02日
    浏览(27)
  • U-net网络详解

    论文地址:https://arxiv.org/abs/1505.04597 学习视频:U-Net网络结构讲解(语义分割)_哔哩哔哩_bilibili 如下图,U-net结构为Encoder-Decoder,左边为Encoder部分,作用是下采样,右边为Decoder部分,作用为上采样 在图中每一个长条代表一个特征层,每一个箭头对应于一种操作 第一步 如下图,

    2024年02月02日
    浏览(24)
  • [记录解决YOLOv5加载权重文件报错问题]AttributeError: Can‘t get attribute ‘DetectionModel‘ on <module ‘models.yolo‘

    1.GitHub(链接: link)找到更新后的v5版本。 2.找到models文件夹下的yolo.py,查找DetectionModel模块,将图片中的代码(Segment部分、BaseModel部分、DetectionModel部分)粘贴至报错的yolo.py里。 3.粘贴完后,运行yolo.py文件

    2024年02月12日
    浏览(30)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包