2017-07-04 8 views
0

私はfreyfaceデータセットをダウンロードしようとしています。 例外が無視されました:<function WeakValueDictionary

この

は私のコードです:

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:(削除)1つの必要な位置引数が欠落: 'WR' 例外では無視:0x000001EB6199D048で.removeを>

はTypeError:)(削除1を逃す必要な位置引数: 'WR' では無視 例外:>

x000001EB61992EA0で.remove

はTypeError:1つの必要な位置引数が欠落(削除)::> はTypeError 0x000001EB61992F28で.remove:で無視 'WR' 例外: 'WR'

答えて

0

私はそれがで固定してしまった(削除)1が欠落は、位置引数を必要とこの投稿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 = [] 
関連する問題