• RuntimeError: Numpy is not available _tensor.py


    E:\Eprogramfiles\Anaconda3\lib\site-packages\torch\_tensor.py in __array__(self, dtype)
        676             return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)
        677         if dtype is None:
    --> 678             return self.numpy()
        679         else:
        680             return self.numpy().astype(dtype, copy=False)
    
    RuntimeError: Numpy is not available


    ====================

    E:\Eprogramfiles\Anaconda3\Scripts>pip show tensorflow
    Name: tensorflow
    Version: 2.4.1
    Summary: TensorFlow is an open source machine learning framework for everyone.
    Home-page: https://www.tensorflow.org/
    Author: Google Inc.
    Author-email: packages@tensorflow.org
    License: Apache 2.0
    Location: e:\eprogramfiles\anaconda3\lib\site-packages
    Requires: grpcio, absl-py, gast, h5py, six, opt-einsum, wheel, flatbuffers, wrapt, google-pasta, astunparse, protobuf, termcolor, numpy, keras-preprocessing, typing-extensions, tensorboard, tensorflow-estimator
    Required-by:

    E:\Eprogramfiles\Anaconda3\Scripts>pip show tensorflow-gpu
    WARNING: Package(s) not found: tensorflow-gpu

    E:\Eprogramfiles\Anaconda3\Scripts>pip show tensorflow-cpu
    WARNING: Package(s) not found: tensorflow-cpu

    E:\Eprogramfiles\Anaconda3\Scripts>

    ====================================


        def __array__(self, dtype=None):
            if has_torch_function_unary(self):
                return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)
            if dtype is None:
                return self.numpy()
            else:
                return self.numpy().astype(dtype, copy=False)


    ====================================

    x = torch.randn(1, requires_grad=True)
    x.numpy()
    # > RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.
    print(x.detach().numpy())
    # > array([-0.13592759], dtype=float32)


    ====================================





  • 相关阅读:
    PowerDesigner小技巧(整理中)
    将日志(Microsoft.Extensions.Logging)添加到.NET Core控制台应用程序
    VMware Workstation Pro 15.5.0 官方版本及激活密钥
    Git 设置和取消代理(SOCKS5代理)
    笔记
    哈希表(Hash Table)与哈希算法
    Elasticsearch分词
    微服务理论
    Elasticsearch与Mysql数据同步
    go语言常用命令
  • 原文地址:https://www.cnblogs.com/emanlee/p/16219485.html
Copyright © 2020-2023  润新知