Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在中忽略异常:<;功能弱值字典_Python_Python 3.x_Machine Learning_Dataset_Pycharm - Fatal编程技术网

Python 在中忽略异常:<;功能弱值字典

Python 在中忽略异常:<;功能弱值字典,python,python-3.x,machine-learning,dataset,pycharm,Python,Python 3.x,Machine Learning,Dataset,Pycharm,我正在尝试下载freyface数据集,并展示几个示例 这是我的代码: import numpy as np import matplotlib.pyplot as plt # configure matplotlib plt.rcParams['figure.figsize'] = (13.5, 13.5) # set default size of plots plt.rcParams['image.interpolation'] = 'nearest' plt.rcParams['ima

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

这是我的代码:

import numpy as np
import matplotlib.pyplot as plt

# configure matplotlib

plt.rcParams['figure.figsize'] = (13.5, 13.5) # set default size of plots
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):
    """Downloads a file from a URL.
    """
    try:
        f = urlopen(url)
        print
        ("Downloading data file " + url + " ...")

        # Open our local file for writing
        with open(os.path.basename(url), "wb") as local_file:
            local_file.write(f.read())
        print
        ("Done.")
  # handle errors
    except HTTPError as e:
        print("HTTP Error:", e.code, url)
    except URLError as e:
        print
        ("URL Error:", 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
    ("Data file %s exists." % data_filename)

# reshape data for later convenience
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))

#visualization
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” 在中忽略异常:。在0x000001EB6199D048处删除>

TypeError:remove()缺少1个必需的位置参数:“wr” 在中忽略异常:。在0x000001EB61992EA0处删除>

TypeError:remove()缺少1个必需的位置参数:“wr” 在中忽略异常:。在0x000001EB61992F28处删除>
TypeError:remove()缺少1个必需的位置参数:“wr”

这篇文章修复了它

--- 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 = []