• 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)


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





  • 相关阅读:
    Android Media Playback 中的MediaPlayer的用法及注意事项(二)
    Android Media Playback 中的MediaPlayer的用法及注意事项(一)
    34. Search for a Range
    33. Search in Rotated Sorted Array
    32. Longest Valid Parentheses
    31. Next Permutation下一个排列
    30. Substring with Concatenation of All Words找出串联所有词的子串
    29. Divide Two Integers
    28. Implement strStr()子串匹配
    27. Remove Element
  • 原文地址:https://www.cnblogs.com/emanlee/p/16219485.html
Copyright © 2020-2023  润新知