异常被忽略在:

我正在尝试下载freyface数据集并展示几个示例。

这是我的代码:

import numpy as np
import matplotlib.pyplot as plt
# 配置matplotlib
plt.rcParams['figure.figsize'] = (13.5, 13.5) # 设置默认图形大小
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
import os
from urllib.request import urlopen, URLError, HTTPError
from scipy.io import loadmat
def fetch_file(url):
    """从URL下载文件。"""
    try:
        f = urlopen(url)
        print("正在下载数据文件 " + url + " ...")
        # 打开本地文件以写入
        with open(os.path.basename(url), "wb") as local_file:
            local_file.write(f.read())
        print("完成。")  # 处理错误
    except HTTPError as e:
        print("HTTP 错误:", e.code, url)
    except URLError as e:
        print("URL 错误:", e.reason, url)
url = "http://www.cs.nyu.edu/~roweis/data/frey_rawface.mat"
data_filename = os.path.basename(url)
if not os.path.exists(data_filename):
    fetch_file(url)
else:
    print("数据文件 %s 已存在。" % data_filename)
# 重塑数据以便后续使用
img_rows, img_cols = 28, 20
ff = loadmat(data_filename, squeeze_me=True, struct_as_record=False)
ff = ff["ff"].T.reshape((-1, img_rows, img_cols))
np.random.seed(42)
n_pixels = img_rows * img_cols
X_train = ff[:1800]
X_val = ff[1800:1900]
X_train = X_train.astype('float32') / 255.
X_val = X_val.astype('float32') / 255.
X_train = X_train.reshape((len(X_train), n_pixels))
X_val = X_val.reshape((len(X_val), n_pixels))
# 可视化
def show_examples(data, n=None, n_cols=20, thumbnail_cb=None):
    if n is None:
        n = len(data)
    n_rows = int(np.ceil(n / float(n_cols)))
    figure = np.zeros((img_rows * n_rows, img_cols * n_cols))
    for k, x in enumerate(data[:n]):
        r = k // n_cols
        c = k % n_cols
        figure[r * img_rows: (r + 1) * img_rows,
        c * img_cols: (c + 1) * img_cols] = x
        if thumbnail_cb is not None:
            thumbnail_cb(locals())
    plt.figure(figsize=(12, 10))
    plt.imshow(figure)
    plt.axis("off")
    plt.tight_layout()
show_examples(ff, n=200, n_cols=25)

但我得到了这个奇怪的错误:

TypeError: remove() 缺少1个必需的位置参数: ‘wr’异常被忽略在:.remove at 0x000001EB6199D048>

TypeError: remove() 缺少1个必需的位置参数: ‘wr’异常被忽略在:.remove at 0x000001EB61992EA0>

TypeError: remove() 缺少1个必需的位置参数: ‘wr’异常被忽略在:.remove at 0x000001EB61992F28>TypeError: remove() 缺少1个必需的位置参数: ‘wr’


回答:

我通过这个帖子解决了这个问题 https://hg.python.org/cpython/rev/2cb530243943

--- a/Lib/weakref.py
+++ b/Lib/weakref.py
@@ -106,7 +106,7 @@ class WeakValueDictionary(collections.Mu
         self, *args = args
         if len(args) > 1:
             raise TypeError('expected at most 1 arguments, got %d' % len(args))
-        def remove(wr, selfref=ref(self)):
+        def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref):
             self = selfref()
             if self is not None:
                 if self._iterating:
@@ -114,7 +114,7 @@ class WeakValueDictionary(collections.Mu
                 else:
                     # Atomic removal is necessary since this function
                     # can be called asynchronously by the GC
-                    _remove_dead_weakref(d, wr.key)
+                    _atomic_removal(d, wr.key)
         self._remove = remove
         # A list of keys to be removed
         self._pending_removals = []

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注