• Python开发过程问题集锦(Continuous updating)


    1.问题:在Python3进行CNN测试时,出现了

    (from warn module)UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing
     artifacts when down-sampling images. warn("Anti-aliasing will be enabled by default in 
    skimage 0.15 to "

    问题原因:因为其默认安装的skimage0.15的版本跟我的Python版本在进行图片采样时发生冲突

    解决方法:卸载skimage 0.15,安装skimage 0.13.0。

    pip3 uninstall scikit-image
    pip3 install scikit-image==0.13.0

    2.问题:启动程序时出现以下错误

    from numpy.lib.arraypad import _validate_lengths
    ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad'

    问题原因:这是在解决skimage0.15版本后出现的问题。找不到_validate_lengths函数,在arraypad.py文件中确实找不到对应的函数,所以找到以前配置过的环境中对应的文件,拷贝这个缺失的函数。

    解决方法:打开终端,进入Python环境,输入以下代码,查看Python3.7安装位置。

    import sys
    print(sys.path)

    找到arraypad.py的位置 user/lib/python3.7/site-packages/numpy/lib/arraypad.py,打开文件后,在954后添加以下代码,保存退出,问题解决。

    def _normalize_shape(ndarray, shape, cast_to_int=True):
        """
        Private function which does some checks and normalizes the possibly
        much simpler representations of ‘pad_width‘, ‘stat_length‘,
        ‘constant_values‘, ‘end_values‘.
    
        Parameters
        ----------
        narray : ndarray
            Input ndarray
        shape : {sequence, array_like, float, int}, optional
            The width of padding (pad_width), the number of elements on the
            edge of the narray used for statistics (stat_length), the constant
            value(s) to use when filling padded regions (constant_values), or the
            endpoint target(s) for linear ramps (end_values).
            ((before_1, after_1), ... (before_N, after_N)) unique number of
            elements for each axis where `N` is rank of `narray`.
            ((before, after),) yields same before and after constants for each
            axis.
            (constant,) or val is a shortcut for before = after = constant for
            all axes.
        cast_to_int : bool, optional
            Controls if values in ``shape`` will be rounded and cast to int
            before being returned.
    
        Returns
        -------
        normalized_shape : tuple of tuples
            val                               => ((val, val), (val, val), ...)
            [[val1, val2], [val3, val4], ...] => ((val1, val2), (val3, val4), ...)
            ((val1, val2), (val3, val4), ...) => no change
            [[val1, val2], ]                  => ((val1, val2), (val1, val2), ...)
            ((val1, val2), )                  => ((val1, val2), (val1, val2), ...)
            [[val ,     ], ]                  => ((val, val), (val, val), ...)
            ((val ,     ), )                  => ((val, val), (val, val), ...)
    
        """
        ndims = ndarray.ndim
    
        # Shortcut shape=None
        if shape is None:
            return ((None, None), ) * ndims
    
        # Convert any input `info` to a NumPy array
        shape_arr = np.asarray(shape)
    
        try:
            shape_arr = np.broadcast_to(shape_arr, (ndims, 2))
        except ValueError:
            fmt = "Unable to create correctly shaped tuple from %s"
            raise ValueError(fmt % (shape,))
    
        # Cast if necessary
        if cast_to_int is True:
            shape_arr = np.round(shape_arr).astype(int)
    
        # Convert list of lists to tuple of tuples
        return tuple(tuple(axis) for axis in shape_arr.tolist())
    
    
    def _validate_lengths(narray, number_elements):
        """
        Private function which does some checks and reformats pad_width and
        stat_length using _normalize_shape.
    
        Parameters
        ----------
        narray : ndarray
            Input ndarray
        number_elements : {sequence, int}, optional
            The width of padding (pad_width) or the number of elements on the edge
            of the narray used for statistics (stat_length).
            ((before_1, after_1), ... (before_N, after_N)) unique number of
            elements for each axis.
            ((before, after),) yields same before and after constants for each
            axis.
            (constant,) or int is a shortcut for before = after = constant for all
            axes.
    
        Returns
        -------
        _validate_lengths : tuple of tuples
            int                               => ((int, int), (int, int), ...)
            [[int1, int2], [int3, int4], ...] => ((int1, int2), (int3, int4), ...)
            ((int1, int2), (int3, int4), ...) => no change
            [[int1, int2], ]                  => ((int1, int2), (int1, int2), ...)
            ((int1, int2), )                  => ((int1, int2), (int1, int2), ...)
            [[int ,     ], ]                  => ((int, int), (int, int), ...)
            ((int ,     ), )                  => ((int, int), (int, int), ...)
    
        """
        normshp = _normalize_shape(narray, number_elements)
        for i in normshp:
            chk = [1 if x is None else x for x in i]
            chk = [1 if x >= 0 else -1 for x in chk]
            if (chk[0] < 0) or (chk[1] < 0):
                fmt = "%s cannot contain negative values."
                raise ValueError(fmt % (number_elements,))
        return normshp
    View Code

    3.问题:Pycharm运行程序时出现如下错误

    问题原因:PyCharm没有停下项目的情况下,关闭IDE.或者是之前的项目没有停掉,又一次运行了本项目.

    解决方法:很简单,杀死进程.

    ps aux  # 用ps -A查看所有进程

    找到程序进程

    杀死进程: 
    kill -9 PID # PID是进程号

    很想高飞,但我不能;不想天空,剩我一人。
  • 相关阅读:
    【Redis过期Key监听】
    【ElasticSearch】ES线上脏数据处理
    【MySQL】实现线上千万数据表添加字段操作以及缓存刷新
    【转】【堆外内存】堆内内存与堆外内存
    【Redis连接超时】记录线上RedisConnectionFailureException异常排查过程
    【ElasticSearch】ES 读数据,写数据与搜索数据的过程
    【ElasticSearch】shards,replica,index之间的关系
    tomorrow多线程启动
    request接口下载附件
    request接口上传附件
  • 原文地址:https://www.cnblogs.com/lixiansheng/p/10293323.html
Copyright © 2020-2023  润新知