zoukankan      html  css  js  c++  java
  • 3-31学习笔记

    1.命令

    lsmod | grep nvidia
    》》
    nvidia              19472384  9
    ipmi_msghandler        53248  4 ipmi_devintf,ipmi_si,nvidia,ipmi_ssif
    
    modinfo nvidia

    用百度搜索找到了这个,https://blog.csdn.net/ddqqfree123/article/details/52388337,然后提到了这个:https://forums.developer.nvidia.com/t/ubuntu-12-04-error-cudagetdevicecount-returned-30/34006/2,里面对应的解决办法是:

    sudo modinfo nvidia-uvm
    #输出很多的信息,然后
    sudo modprobe -v nvidia-uvm
    #又输出很多信息,之后
    ./deviceQuery
    #就PASS了,

    之前尝试了这里:https://github.com/tensorflow/tensorflow/issues/5777 ||https://stackoverflow.com/questions/58595291/runtime-error-999-when-trying-to-use-cuda-with-pytorch#comment103505439_58595291 里一系列的rmmod,出了nvidia都说not loaded,而nvidia模块in use,然后又用上面的第一个命令查看。

    3.torch查看gpu信息

    https://blog.csdn.net/nima1994/article/details/83001910

    torch.cuda.is_available()
    cuda是否可用;
    
    torch.cuda.device_count()
    返回gpu数量;
    
    torch.cuda.get_device_name(0)
    返回gpu名字,设备索引默认从0开始;
    
    torch.cuda.current_device()
    返回当前设备索引;

    2.python继承dict类

    http://www.coolpython.net/python_senior/pytip/special_dict.html,原来dict类也可以继承,是一个dict对象,需要实现__setitem__方法。

    class DoubleDict(dict):
    
        def __delitem__(self, key):     # 删除一个key, 也必须删除value
            value = super().pop(key)
            super().pop(value, None)
    
        def __setitem__(self, key, value):      # 先设置key-value, 再设置value-key
            super().__setitem__(key, value)
            super().__setitem__(value, key)
    
        def update(self, another):
            for key, value in another.items():
                self.__setitem__(key, value)
    
        def __repr__(self):
            return f"{type(self).__name__}({super().__repr__()})"
    
    dic = DoubleDict()
    print(dic)
    dic[''] = 1
    dic[''] = 2
    
    print(dic[''])
    print(dic[2])
    
    dic.update({'': 3})
    print(dic[3])

    输出:

    DoubleDict({})
    1
    二
    三
    1. __delitem__ 是删除给定键对应的值
    2. __setitem__ 设置给定键的值
    3. update是更新字典的方法
    4. __repr__ 是显示对象信息的方法,由于字典的该方法显示的是字典的内容,因此进行重载,让其显示出类的名字

    3.dir(tf.losses)

    https://www.runoob.com/python/python-func-dir.html

     dir不带参数,返回当前范围的函数和变量,带参数,返回参数所包含的函数和变量。

    >>> dir()
    ['__annotations__', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'tf']
    
    >>> dir(tf.losses)
    ['Reduction', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 

    'absolute_difference', 'add_loss', 'compute_weighted_loss', 'cosine_distance', 'get_losses', 'get_regularization_loss', 'get_regularization_losses',
    'get_total_loss', 'hinge_loss', 'huber_loss', 'log_loss', 'mean_pairwise_squared_error', 'mean_squared_error', 'sigmoid_cross_entropy',
    'softmax_cross_entropy', 'sparse_softmax_cross_entropy']
    >>> dir(keras.activations)
    ['K', 'Layer', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', 
    '__name__', '__package__', '__spec__', 'absolute_import', 'deserialize', 
    'deserialize_keras_object', 'division', 'elu', 'exponential', 'get', 'hard_sigmoid', 
    'linear', 'print_function', 'relu', 'selu', 'serialize', 'sigmoid', 'six', 'softmax', 
    'softplus', 'softsign', 'tanh', 'warnings']
    >>> 'zinb' in dir(tf.losses)
    False
    >>> 'nb' in dir(tf.losses)
    False
    >>> 'zinb' in dir(keras.activations)
    False
    >>> 'nb' in dir(keras.activations)
    False
    #木有的呀

     4.tensorflow_probability

    要使用它,还要安装最新版的tensorflow。

  • 相关阅读:
    第二阶段第九天
    第二阶段第八天
    一轮项目冲刺——移山小分队(3)
    一轮项目冲刺——移山小分队(2)
    典型用户和用户场景
    一轮项目冲刺——移山小分队
    寻找水王
    NABCD需求分析
    每日记录01
    二维数组最大连通和的求解
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/12606338.html
Copyright © 2011-2022 走看看