深度学习训练存在的问题

1. AttributeError: module ‘cv2.cv2’ has no attribute 'saliency

  File "C:\Users\64883\Desktop\contrastive-unpaired-translation-master\models\cut_model.py", line 188, in compute_G_loss
    self.loss_NCE = self.calculate_NCE_loss(self.real_A, self.fake_B)
  File "C:\Users\64883\Desktop\contrastive-unpaired-translation-master\models\cut_model.py", line 209, in calculate_NCE_loss
    feat_k_pool, sample_ids = self.netF(feat_k, self.opt.num_patches, None)
  File "D:\Anaconda3\envs\pytorch_envs\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "C:\Users\64883\Desktop\contrastive-unpaired-translation-master\models\networks.py", line 567, in forward
    detector = cv2.saliency.StaticSaliencyFineGrained_create()  # create a saliency detector
AttributeError: module 'cv2.cv2' has no attribute 'saliency'

可能的解决方法
(1)卸载opencv和opencv-contrib-python,然后重新安装opencv-contrib-python
(2)确保你的opencv和opencv-contrib-python的版本相同,例如都是4.5.3
(3)使用cv2而不是cv2.cv2来导入模块,例如import cv2 as cv2
采用了第一种方法

(pytorch_envs) C:\Users\64883\Desktop\contrastive-unpaired-translation-master>pip uninstall opencv-python
Found existing installation: opencv-python 4.5.2.52
Uninstalling opencv-python-4.5.2.52:
  Would remove:
    d:\anaconda3\envs\pytorch_envs\lib\site-packages\cv2\*
    d:\anaconda3\envs\pytorch_envs\lib\site-packages\opencv_python-4.5.2.52.dist-info\*
Proceed (y/n)? y
  Successfully uninstalled opencv-python-4.5.2.52

2. ValueError: check_hostname requires server_hostname

  File "D:\Anaconda3\envs\pytorch_envs\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 432, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "D:\Anaconda3\envs\pytorch_envs\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 474, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "D:\Anaconda3\envs\pytorch_envs\lib\ssl.py", line 423, in wrap_socket
    session=session
  File "D:\Anaconda3\envs\pytorch_envs\lib\ssl.py", line 827, in _create
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname

可能的解决方法
(1)升级或降级你的urllib3或requests库,使它们的版本匹配
(2)关闭你的网络代理(VPN),或者在.condarc文件里添加网络代理的端口号
(3)检查你的requests请求是否有正确的server_hostname参数
采用了第二种方法

(pytorch_envs) C:\Users\64883\Desktop\contrastive-unpaired-translation-master>pip install opencv-contrib-python
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting opencv-contrib-python
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f3/8b/9d010c60a2254e810ea2bd4a8645f9e12dff3ee8f2de12e7b8b38cdec561/opencv_contrib_python-4.7.0.72-cp37-abi3-win_amd64.whl (44.9 MB)
     |████████████████████████████████| 44.9 MB 328 kB/s
Requirement already satisfied: numpy>=1.17.0 in d:\anaconda3\envs\pytorch_envs\lib\site-packages (from opencv-contrib-python) (1.21.5)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.7.0.72

都解决了!

猜你喜欢

转载自blog.csdn.net/qq_40721108/article/details/129410224