小编Ero*_*mic的帖子

找到PIL/PILLOW正在使用的libjpeg

我收到一个错误,在两台不同的计算机上读取相同的lena.jpg文件会产生两个不同的校验和.

甚至更奇怪的是,当我运行md5sum lena.jpg时,我在两台机器上获得相同的md5总和,因此文件是相同的.

此外,当我加载png而不是jpeg时,数字似乎匹配.这让我相信Pillow在两台不同的机器上,或者至少是用于读取jpeg文件的库之间存在脱节.

有没有办法检查Pillow正在使用哪个版本的libjpeg(最好是在Python中)?

两台计算机都是Ubuntu,虽然一台是12.04,一台是14.04(我也在Mac上测试了它,并且得到了与14.04盒子相同的值)

python libjpeg python-imaging-library pillow

3
推荐指数
1
解决办法
1899
查看次数

sphinx 可以忽略 python 文档字符串中的某些标签吗?

我正在使用 sphinx 记录我的项目,并使用 sphinxcontrib.napoleon 扩展,它允许我使用谷歌风格的文档字符串。

这是我的项目中的一个函数

def nn_normalized_weight(normweight_fn, qaid2_nns, qreq_):
    """
    Weights nearest neighbors using the chosen function

    Args:
        normweight_fn (func): chosen weight function e.g. lnbnn
        qaid2_nns (dict): query descriptor nearest neighbors and distances. qaid -> (qfx2_nnx, qfx2_dist)
        qreq_ (QueryRequest): hyper-parameters

    Returns:
        tuple(dict, dict) : (qaid2_weight, qaid2_selnorms)

    Example:
        >>> from ibeis.model.hots.nn_weights import *
        >>> from ibeis.model.hots import nn_weights
        >>> ibs, daid_list, qaid_list, qaid2_nns, qreq_ = nn_weights.testdata_nn_weights()
        >>> qaid = qaid_list[0]
        >>> #----
        >>> normweight_fn = lnbnn_fn
        >>> tup1 = nn_weights.nn_normalized_weight(normweight_fn, …
Run Code Online (Sandbox Code Playgroud)

python python-sphinx

2
推荐指数
1
解决办法
3295
查看次数

当我分配大量的ndarray时,numpy空做什么?

我看着内存中的numpy数组消耗了多少空间,并且发现了一个奇怪的行为:

我跑的时候 x = np.empty((1000000, 7, 64, 64), dtype=np.uint8)

我的16GB内存的计算机没有崩溃。相反,它分配了2GB内存时运行顺利。

此numpy阵列的重量应为26.70 GB,但似乎正在发生一些延迟。当我添加一个时,懒惰立即停止,我的程序挂起,并且它们得到一个MemoryError

我想知道引擎盖下是如何做的。

我看了一眼numpy.core.multiarray,发现numpy/core/src/multiarray/multiarraymodule.c下面这段代码似乎是空的定义:

static PyObject *
array_empty(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
{

    static char *kwlist[] = {"shape","dtype","order",NULL};
    PyArray_Descr *typecode = NULL;
    PyArray_Dims shape = {NULL, 0};
    NPY_ORDER order = NPY_CORDER;
    npy_bool is_f_order;
    PyArrayObject *ret = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&", kwlist,
                PyArray_IntpConverter, &shape,
                PyArray_DescrConverter, &typecode,
                PyArray_OrderConverter, &order)) {
        goto fail;
    }

    switch (order) {
        case NPY_CORDER:
            is_f_order = NPY_FALSE;
            break;
        case NPY_FORTRANORDER: …
Run Code Online (Sandbox Code Playgroud)

c python memory-management numpy linux-kernel

2
推荐指数
1
解决办法
429
查看次数

加载的pickle数据在内存中比在磁盘上大得多并且似乎泄漏.(Python 2.7)

我有记忆问题.我有一个用Python 2.7 cPickle模块编写的pickle文件.该文件在磁盘上为2.2GB.它包含各种字典,列表和numpy数组嵌套的字典.

当我加载这个文件(再次在Python 2.7上使用cPickle)时,python进程最终使用5.13GB的内存.然后,如果我删除对加载数据的引用,则数据使用量将下降2.79GB.在程序结束时,还有另外2.38GB尚未清理.

是否有一些cPickle保留在后端的缓存或memoization表?这些额外数据来自哪里?有没有办法清除它?

加载的cPickle中没有自定义对象,只有dicts,lists和numpy数组.我无法理解为什么它的表现如此.


令人不快的例子

这是我编写的一个简单脚本来演示行为:

from six.moves import cPickle as pickle
import time
import gc
import utool as ut

print('Create a memory tracker object to snapshot memory usage in the program')
memtrack = ut.MemoryTracker()

print('Print out how large the file is on disk')
fpath = 'tmp.pkl'
print(ut.get_file_nBytes_str('tmp.pkl'))

print('Report memory usage before loading the data')
memtrack.report()
print(' Load the data')
with open(fpath, 'rb') as file_:
    data = pickle.load(file_)

print(' Check how much data it used')
memtrack.report()

print(' …
Run Code Online (Sandbox Code Playgroud)

python numpy pickle python-2.7

2
推荐指数
1
解决办法
992
查看次数