【红外彩色化】一些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() 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(': 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() 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()注释掉
【红外彩色化】一些bug的简单记录及可能的解决方法_第1张图片

  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

你可能感兴趣的:(python,深度学习,人工智能,pytorch,图像处理)