GVKun编程网logo

将 numpy 或 torch 数组迭代绘制为图像并打开按键(使用numpy创建全1数组)

2

对于想了解将numpy或torch数组迭代绘制为图像并打开按键的读者,本文将是一篇不可错过的文章,我们将详细介绍使用numpy创建全1数组,并且为您提供关于'torch.backends.cudnn.

对于想了解将 numpy 或 torch 数组迭代绘制为图像并打开按键的读者,本文将是一篇不可错过的文章,我们将详细介绍使用numpy创建全1数组,并且为您提供关于'torch.backends.cudnn.deterministic=True' 和 'torch.set_deterministic(True)' 之间有什么区别?、(Libtorch) FP16 张量导致 Torch::max() 和 torch::sqrt() 的 C10error、Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案、Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable的有价值信息。

本文目录一览:

将 numpy 或 torch 数组迭代绘制为图像并打开按键(使用numpy创建全1数组)

将 numpy 或 torch 数组迭代绘制为图像并打开按键(使用numpy创建全1数组)

我找到了一个让我满意的解决方案,它涉及创建一个类对象 -

希望有人觉得它有用:

import matplotlib.pyplot as plt

class plot_change():

    def __init__(self,data):
        self.data = data
        self.i = 0
        self.fig = plt.figure(1)
        self.ax1 = self.fig.add_subplot(111,aspect='equal')


    def plot(self,e):
        self.fig = plt.figure(1)
        ax1 = self.fig.add_subplot(111,aspect='equal')
        ax1.cla()
        ax1.imshow(self.data[self.i,:,:])
        self.i += 1

    def start_plotting(self):
        cid = self.fig.canvas.mpl_connect('key_press_event',self.plot)
        plt.show()


#now to see that it works
import plot_change
import torch
data = torch.rand((700,64,64))
plotter = plot_change(data)
plotter.start_plotting()

'torch.backends.cudnn.deterministic=True' 和 'torch.set_deterministic(True)' 之间有什么区别?

'torch.backends.cudnn.deterministic=True' 和 'torch.set_deterministic(True)' 之间有什么区别?

如何解决''torch.backends.cudnn.deterministic=True'' 和 ''torch.set_deterministic(True)'' 之间有什么区别??

我的网络包括“torch.nn.MaxPool3d”,根据 PyTorch 文档(版本 1.7 - https://pytorch.org/docs/stable/generated/torch.set_deterministic.html#torch.set_deterministic),当 cudnn 确定性标志打开时,它会抛出 RuntimeError,但是,当我插入代码“torch.backends”时.cudnn.deterministic=True'' 在我的代码开头,没有 RuntimeError。为什么该代码不抛出 RuntimeError? 我想知道该代码是否能保证我的训练过程的确定性计算。

解决方法

function getAnnotationsFromDocument(docId,callback){ initDB(); var async = require(''async''); async.waterfall([ function authorize(callback){ //checkAuthorization (...) },function getRfpdocAnnotations(auth,metadata,callback){ //call to DB (...) },function processRfpdocAnnotations(rfpDocAnnotations,callback){ (...) callback(null,annotationsList); } ],function (err,result) { if(err) { callback(err); } else { callback(null,result); } }); } 适用于 CUDA 卷积运算,仅此而已。因此,不,它不能保证您的训练过程是确定性的,因为您还使用了 torch.backends.cudnn.deterministic=True,其后向函数对于 CUDA 是不确定的。

另一方面,

torch.nn.MaxPool3d 会影响此处列出的所有正常非确定性操作(请注意,torch.set_deterministic() 在 1.8 中已重命名为 set_deterministic):https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html?highlight=use_deterministic#torch.use_deterministic_algorithms

正如文档所述,某些列出的操作没有确定性的实现。因此,如果设置了 use_deterministic_algorithms,它们将抛出错误。

如果您需要使用诸如 torch.use_deterministic_algorithms(True) 之类的非确定性操作,那么目前,您的训练过程无法确定性——除非您自己编写自定义确定性实现。或者您可以打开一个 GitHub 问题请求确定性实现:https://github.com/pytorch/pytorch/issues

此外,您可能想查看此页面:https://pytorch.org/docs/stable/notes/randomness.html

(Libtorch) FP16 张量导致 Torch::max() 和 torch::sqrt() 的 C10error

(Libtorch) FP16 张量导致 Torch::max() 和 torch::sqrt() 的 C10error

如何解决(Libtorch) FP16 张量导致 Torch::max() 和 torch::sqrt() 的 C10error

我在定义 FP16 张量并使用 torch::max() 和 torch::sqrt() 时遇到了 c10 错误。代码如下所示:

  1. float test_float[3][3] = { {1.0,2.0,3.0},{4.0,5.0,6.0 },{7.0,8.0,9.0} };
  2. torch::Tensor test_float_tensor = torch::from_blob(test_float,{ 3,3
  3. }).to(at::kcpu).to(torch::kFloat16);
  4. torch::sqrt(test_float_tensor);
  5. torch::max(test_float_tensor,1,true);

enter image description here

如果我将 FP16 张量更改为 FP32 张量,错误就消失了。

  1. float test_float[3][3] = { {1.0,3
  2. }).to(at::kcpu).to(torch::kFloat32);
  3. torch::sqrt(test_float_tensor);
  4. torch::max(test_float_tensor,true);

为什么会这样?我注意到有人说 cpu 不支持 FP16 张量,但是我发现 cpu 中的某些函数可以用于 FP16 张量,例如 torch::sum()。

Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案

Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案

如何解决Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案?

希望有人能在这里提供帮助。我一直在绕圈子一段时间。我只是想设置一个 python 脚本,它将一些 json 数据从 REST API 加载到云数据库中。我在 Anaconda 上设置了一个虚拟环境(因为 GCP 库推荐这样做),安装了依赖项,现在我只是尝试导入库并向端点发送请求。 我使用 Conda(和 conda-forge)来设置环境并安装依赖项,所以希望一切都干净。我正在使用带有 Python 扩展的 VS 编辑器作为编辑器。 每当我尝试运行脚本时,我都会收到以下消息。我已经尝试了其他人在 Google/StackOverflow 上找到的所有解决方案,但没有一个有效。我通常使用 IDLE 或 Jupyter 进行脚本编写,没有任何问题,但我对 Anaconda、VS 或环境变量(似乎是相关的)没有太多经验。 在此先感谢您的帮助!

  \Traceback (most recent call last):
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\__init__.py",line 22,in <module>
from . import multiarray
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\multiarray.py",line 12,in <module>
from . import overrides
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\overrides.py",line 7,in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load Failed while importing _multiarray_umath: The specified module Could not be found.

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
File "c:\API\citi-bike.py",line 4,in <module>
import numpy as np
File "C:\Conda\envs\gcp\lib\site-packages\numpy\__init__.py",line 150,in <module>
from . import core
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\__init__.py",line 48,in <module>
raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions Failed. This error can happen for
many reasons,often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

* The Python version is: python3.9 from "C:\Conda\envs\gcp\python.exe"
* The NumPy version is: "1.21.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load Failed while importing _multiarray_umath: The specified module Could not be found.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable

Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable

如何解决Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: ''numpy.ndarray'' object is not callable?

晚安, 尝试打印以下内容时,我在 jupyter 中遇到了 numpy 问题,并且得到了一个 错误: 需要注意的是python版本是3.8.8。 我先用 spyder 测试它,它运行正确,它给了我预期的结果

使用 Spyder:

import numpy as np
    for i in range (5):
        n = np.random.rand ()
    print (n)
Results
0.6604903457995978
0.8236300859753154
0.16067650689842816
0.6967868357083673
0.4231597934445466

现在有了 jupyter

import numpy as np
    for i in range (5):
        n = np.random.rand ()
    print (n)
-------------------------------------------------- ------
TypeError Traceback (most recent call last)
<ipython-input-78-0c6a801b3ea9> in <module>
       2 for i in range (5):
       3 n = np.random.rand ()
---->  4 print (n)

       TypeError: ''numpy.ndarray'' object is not callable

感谢您对我如何在 Jupyter 中解决此问题的帮助。

非常感谢您抽出宝贵时间。

阿特,约翰”

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

今天关于将 numpy 或 torch 数组迭代绘制为图像并打开按键使用numpy创建全1数组的分享就到这里,希望大家有所收获,若想了解更多关于'torch.backends.cudnn.deterministic=True' 和 'torch.set_deterministic(True)' 之间有什么区别?、(Libtorch) FP16 张量导致 Torch::max() 和 torch::sqrt() 的 C10error、Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案、Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable等相关知识,可以在本站进行查询。

本文标签: