【红外彩色化】一些bug的简单记录及可能的解决方法

  1. SyntaxError: invalid syntax
    input_B = input_B.cuda(self.gpu_ids[0], async=True)
    解决方法:删除async=True即可
  2. ZeroDivisionError: division by zero
    print(‘Avarage Distances: %.3f’ % (sum(dist_) / len(im0_path_list)))
    在除数组成的lst中,最后一个元素为0,当使用到最后一个元素0作为除数时,会提示ZeroDivisionError: division by zero
    解决办法: 要保证除数不为0,为避免抛异常可以加入判断语句,遇到0不做除法
  3. range等比取值
    解决方法:range(0,480,6) 0,6,12…
  4. TypeError: ‘NoneType’ object is not subscriptable
    加载数据为空类型,应该仔细查看自己数据路径
  5. RuntimeError:
    An attempt has been made to start a new process before the
    current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:
    if name == ‘main’:
    freeze_support()

    The “freeze_support()” line can be omitted if the program
    is not going to be frozen to produce an executable.

    解决方法: 在train.py中加入 if name == ‘main’:
  6. IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number
    解决方法:修改loss.data[0]为loss.item(),例如:
        return OrderedDict([('G_GAN', self.loss_G_GAN.data[0]),
                            ('G_L1', self.loss_G_L1.data[0]),
                            ('D_real', self.loss_D_real.data[0]),
                            ('D_fake', self.loss_D_fake.data[0])
                            ])
        return OrderedDict([('G_GAN', self.loss_G_GAN.item()),
                            ('G_L1', self.loss_G_L1.item()),
                            ('D_real', self.loss_D_real.item()),
                            ('D_fake', self.loss_D_fake.item())
                            ])
  1. requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘localhost’, port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000029C535BCC08>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
    解决方法:在终端输入python -m visdom.server
  2. TypeError: initialize() takes 1 positional argument but 2 were given
    模型定义错误,看是否加载到模型
  3. ImportError: bad magic number in ‘options’: b’\x03\xf3\r\n’
    解决方法:删除项目中所有的 .pyc 文件
  4. RuntimeError: [enforce fail at …\c10\core\CPUAllocator.cpp:75] data. DefaultCPUAllocator: not enough memory: you tried to allocate 981552 bytes. Buy new RAM!
    解决方法:内存不够,建议重启pycharm
  5. ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 256 and the array at index 1 has size 400
    原因是设计的尺寸超过原先图片的尺寸,解决方法修改index1 的尺寸,必须≤256
  6. RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)
    错误的原因是nn.Linear() 维度出现错误,重新检查
  7. TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of: * (tuple of ints size, *, tuple of names names, torch.memory_format memory_format, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
    产生的原因是因为在python3中两个整型相除得到的是浮点型,例如:4/2=2.0,而在构建卷积时的参数要求时整型
        self.hidden_channel = in_channel * r

变成

        self.hidden_channel = int(in_channel * r)
  1. ImportError: attempted relative import with no known parent package
    用绝对路径代替相对路径
from .layers import LayerNorm, PositionalEncodingFourier

变成

from models.layers import LayerNorm, PositionalEncodingFourier
  1. IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number
 self.losses[loss_name] = losses[loss_name].data[0]

变成

 self.losses[loss_name] = losses[loss_name].item()
  1. Downloading scripts, this may take a little while
    找到visdom所在的文件夹
    比如用conda下载,所在文件夹为:
D:\Anaconda3\envs\paddlepaddle\Lib\site-packages\visdom

打开server文件中的run_server.py
将download_scripts_and_run函数中的download_scripts()注释掉
在这里插入图片描述

  1. ERROR:tornado.general:Could not open static file D:\\Anaconda3\\envs\\paddlepaddle\\lib\\site-packages\\visdom\\static\\css\\bootstrap.min.css
    参考链接
    下载好文件,找到visdom-master\py\visdom\static\index.html,替换本地中的index.html
<!--

Copyright 2017-present, Facebook, Inc.
All rights reserved.

This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.

-->

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="shortcut icon" href="favicon.png">

    <!-- Bootstrap & jQuery -->
    <link rel="stylesheet" href={{ static_url("css/bootstrap.min.css") }}>
    <script src={{ static_url("js/jquery.min.js") }}></script>
    <script src={{ static_url("js/bootstrap.min.js") }}></script>

    <link rel="stylesheet" href={{ static_url("css/react-resizable-styles.css") }}>
    <link rel="stylesheet" href={{ static_url("css/react-grid-layout-styles.css") }}>

    <!-- Other deps -->
    <script src={{ static_url("js/react-react.min.js") }}></script>
    <script src={{ static_url("js/react-dom.min.js") }}></script>
    <script src={{ static_url("fonts/layout_bin_packer") }}></script>

    <!-- Mathjax -->
    <script type="text/javascript" async src={{ static_url("js/mathjax-MathJax.js") }}></script>

    <!-- Plotly -->
    <script src={{ static_url("js/plotly-plotly.min.js") }}></script>

    <!-- Custom styles for this template -->
    <script>
    // TODO: this is not great. Should probably be an endpoint with a JSON
    // response or the first thing the socket sends back.
    var ENV_LIST = [
      {% for item in items %}
      '{{escape(item)}}',
      {% end %}
    ];
    var ACTIVE_ENV = '{{escape(active_item)}}';
    var USER = '{{escape(user)}}';

    // Plotly setup
    window.PLOTLYENV = window.PLOTLYENV || {};
    window.PLOTLYENV.BASE_URL = 'https://plot.ly';

    </script>
    <script src={{ static_url("js/main.js") }}></script>
    <link rel="stylesheet" href={{ static_url("css/style.css") }}>

    <title>visdom</title>
    <!-- <link rel="icon" href="http://example.com/favicon.png"> -->
  </head>

  <body>
    <noscript>JS is required</noscript>
    <div id="app"></div>
  </body>
</html>


或者直接将资源中的static替换visdom文件夹下的static

18. EOFError: Ran out of input
解决方法:在训练模型的时候,遇到了EOFError: Ran out of input这个问题,绝大多数的情况下,是torch.utils.data.DataLoader在windows下的特有错误,该函数里面有个参数num_workers表示进程个数,在windows下改为0就可以了,在彩色化中,修改的参数是num_threads。

19. pip下载扩展包时报错 ValueError: check_hostname requires server_hostname
解决方法:在设置中关闭网络代理服务器即可成功下载安装扩展包(亲测好用)。

20. 训练的时候想同时测试一下,出现问题

RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

原因:多进程需要在main函数中运行
解决方法:加main函数,在main函数中执行(未尝试)

21. 新的红外数据集
CAMEL Dataset
官网

22. OSError: [Errno 98] Address already in use

ps -fA | grep python

在这里插入图片描述

kill 2742102
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值