线程Thread-7错误中的异常

时间:2018-06-28 01:25:01

标签: python-2.7 queue python-multithreading numpy-ndarray

当我尝试使用下面的user_name和Item dict运行下面的函数时,出现以下错误。我只提供了Item dict的示例,因为它非常大。这是一种压缩的numpy图片数据格式。我是队列和线程程序包的新手。我正在Mac上工作,并从jupyter笔记本中的某个单元运行代码,这可能是问题之一吗?我还从更大的dict中采样了Item dict,因此原始dict中的某些dict键会丢失。对于造成此错误的原因的任何提示将不胜感激。

Code:

import sys
import math
import random
import time
from PIL import Image
import Queue
import numpy as np
import threading
from cStringIO import StringIO
import tensorflow as tf

def load_image_async():
    while True:
        (uuu,iii,jjj)=sample(user_train)
        jpg1=np.uint8(np.asarray(Image.open(StringIO(Item[iii]['imgs'])).convert('RGB').resize((224,224))))
        jpg2=np.uint8(np.asarray(Image.open(StringIO(Item[jjj]['imgs'])).convert('RGB').resize((224,224))))
        sess.run(batch_train_queue_op,feed_dict={queueu:np.asarray([uuu]),
                                                 queuei:np.asarray([iii]),
                                                 queuej:np.asarray([jjj]),
                                                 queueimage1:jpg1,queueimage2:jpg2,
                                                })


Data:


Item

{1: {'asin': 'B00APT3MHO',
  'c': array([False, False, False,  True, False, False], dtype=bool),
  'categories': [['Clothing, Shoes & Jewelry', 'Women', 'Clothing', 'Jeans'],
   ['Clothing, Shoes & Jewelry', 'Women', 'Petite', 'Jeans']],
  'imUrl': 'http://ecx.images-amazon.com/images/I/31hFOdT1iiL._SX342_.jpg',
  'imgs': '\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x05\x03\x04\x04\x04\x03\x05\x04\x04\x04\x05\x05\x05\x06\x07\x0c\x08\x07\x07\x07\x07\x0f\x0b\x0b\t\x0c\x11\x0f\x12\x12\x11\x0f\x11\x11\x13\x16\x1c\x17\x13\x14\x1a\x15\x11\x11\x18!\x18\x1a\x1d\x1d\x1f\x1f\x1f\x13\x17"$"\x1e$

…

\xb3\x1ei\x03\nf\x8f\xe4o\xc7n\xc3_s\xd7\x80\xfe\xdd\xfaU\xa5\xef\xc15\xd4\xa5A\xf6\x9d;Q\x85\xe0|r\x03\xe5\x19~\x87 \xff\x00\xc0Eta\xa5j\x89w\xd0\x99\xad\x0f\x81YLr\xb2`\x82\x0e3\x9az\x91\xb7\x01\x8e})\xda\x80\xc5\xc0\x90pYA?Z\x89+\xa5\x14\xb5%\x03o8\xc7\xe3V"\nxS\x90N0j\xbar\xacH\xcdK\x1b\xfc\xa4\x00\x07J\xb8\x11=\x8b\x96\xc1L\xec\x8c\xd8\x19\xe3\xbe+g\xc28\xff\x00\x84\xf3@\x00\xe4\x9dJ\x03\xbb\xd3\xf7\x8b\\\xfa1\x1f6r\xdds\xfd+\xa2\xf0\x1a\xabx\xf3\xc3\xacG\xde\xd4\xa0\xcf\xfd\xfc\x15\xd9\x07\xa1\xcd%\xa9\xfa\x91E\x14W\xcf\x9d\x81E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x07\xff\xd9',
  'price': 20.95,
  'related': {'also_bought': ['B009B1TRXU',
    'B008YWHD56',
    'B008KKMMT4',
    'B00CBT0WDS',
    'B00AOCX3TE'],
   'also_viewed': ['B00EHA6L5W',
    'B008YWHD56',
    'B00HHKSVB6',
    'B00BN0AVXM',
    'B00HHKSSTG',
    'B00AX3EZPK',
    'B00CKFVNRM',
    'B00FP87X48',
    'B00BJFKS5W',
    'B00JGM7DEY',
    'B00BCTHM6S',
    'B009B1TRXU',
    'B00GTJJ0CU',
    'B00FEC2O62',
    'B00FEC2L7O',
    'B00CQUI6BW',
    'B00JGMIWK8',
    'B00D1VTX58',
    'B00GTJIHME',
    'B00IKBSF6C',
    'B00JVGZBB2',
    'B00CKK68OU',
    'B00IKBSQYS',
    'B00BKU5626',
    'B00D2OWBPS',
    'B008KKMMT4',
    'B00FEC2K34',
    'B00E0EHOS8',
    'B008YWEJ9O',
    'B00GRQJQPQ',
    'B00DE6N9GE',
    'B00JPWO3P2',
    'B00BLXR14I',
    'B00AXFF3QS',
    'B00F9NGFFW',
    'B00JPWNUWY',
    'B00AXFIS5G',
    'B00G1WTH4G',
    'B00JPW8ATM',
    'B00JRSE8PE',
    'B00AXFRP8M',
    'B00JM4N8BI',
    'B00JVGZN2E',
    'B00EQ33A7C',
    'B007WADUOY',
    'B00IKBSNDM',
    'B00JGM6F7U',
    'B00D2K4IPS',
    'B00EJ9YTPU',
    'B00APV5T5U',
    'B008OY32LI',
    'B00D13P42C',
    'B00GMDKFXG',
    'B00BMHBDHY',
    'B00CL81XU0',
    'B00D1GI8FO',
    'B00KKB2IX6',
    'B00ACD8O0I',
    'B00CV2ZKAA'],
   'bought_together': ['B008YWHD56']},
  'salesRank': {'Clothing': 365178},
  'title': 'ELLAZHU Women Crew Neck Crane & Fox Short Curling Sleeve T-shirt Onesize HG17'},
 4: {'asin': 'B00F9NGAPM',


user_train:

{0: [{u'asin': u'B00APT3MHO',
   u'helpful': [0, 0],
   u'overall': 5.0,
   'productid': 1,
   u'reviewText': u"Good for someone who likes skinny jeans but doesn't look great in the legging-tight ones. A little stretchy. Not super tight in the knee or ankle, but snug on the thigh and calf.",
   u'reviewTime': u'11 17, 2013',
   u'reviewerID': u'A1JWX45KHE34AL',
   u'reviewerName': u'varnienarsil',
   u'summary': u'Love these jeans',
   u'unixReviewTime': 1384646400},
  {u'asin': u'B00CJ5NH36',
   u'helpful': [0, 0],
   u'overall': 5.0,
   'productid': 2,
   u'reviewText': u"This shirt with it's bold graphic is seriously adorable. I have pretty narrow shoulders, and like the way the sleeves slope off them. The shirt fits loosely in a way that is flattering and I liked the length. I'm no model, but the shirt looks on me as great as it looks in the photo.",
   u'reviewTime': u'11 17, 2013',
   u'reviewerID': u'A1JWX45KHE34AL',
   u'reviewerName': u'varnienarsil',
   u'summary': u'As cute as it looks',
   u'unixReviewTime': 1384646400},
  {u'asin': u'B00F9NGAPM',
   u'helpful': [1, 1],
   u'overall': 3.0,
   'productid': 4,
   u'reviewText': u"The shirt is a little flowy-er than I expected. I like the way it drapes, but the arms are a bit loose (and on me, short—I'm pretty tall). Has a sort of after-yoga feel rather than the urban feel I was looking for. Super comfortable.",
   u'reviewTime': u'11 17, 2013',
   u'reviewerID': u'A1JWX45KHE34AL',
   u'reviewerName': u'varnienarsil',
   u'summary': u"Like, don't love",
   u'unixReviewTime': 1384646400}],
 1: [{u'asin': u'B000LYFF46',
   u'helpful': [0, 0],
   u'overall': 3.0,
   'productid': 5,
   u'reviewText': u"I selected "fit as expected", but they just are not comfortable.  There is a ridge inside the top of the heel.  It feels lumpy and digs in a little.  The arch support feels inadequate.  Maybe the heel would soften, but I won't risk it and will return them.",
   u'reviewTime': u'03 3, 2014',
   u'reviewerID': u'A2YHF6O2D37PMX',
   u'reviewerName': u'DCP',
   u'summary': u'Just not comfortable for me',
   u'unixReviewTime': 1393804800},
  {u'asin': u'B005FPAC8K',
   u'helpful': [3, 3],
   u'overall': 1.0,
   'productid': 6,
   u'reviewText': u"May 27:  I've worn them 3-4 times each since May 7, and I have to lower my original rating from 3 stars to 1.  I wore the blue pair for shopping yesterday and came home in pain.  They have stretched so badly that I was walking awkwardly.  I'd have had better control with flipflops and more comfort being barefoot.  In addition, the footbed felt hard and lumpy as the day went on.  Also, the red color of the insole on the other pair stains kneehighs, and it doesn't wash out.I tried on 2 other pair of Easy Street sandals/shoes recently and found them to fit as poorly as these.  Easy Street is not a brand I can wear.May 7:  I bought two pairs of this sandal, one red, one blue.  The size I wanted (7N) was not available in both colors, so I ended up ordering one 6.5M and one 7N.  Strangely, the 6.5 is actually slightly longer than the 7.  The M is a tiny fraction wider than the N, but both are loose.  They are not uncomfortable, but I would be much happier if they were not so wide.  For the price, they are okay, but I will not buy more.  They just feel sloppy as I walk.",
   u'reviewTime': u'05 7, 2012',
   u'reviewerID': u'A2YHF6O2D37PMX',
   u'reviewerName': u'DCP',
   u'summary': u'Lowered my rating',
   u'unixReviewTime': 1336348800},
  {u'asin': u'B007IL5PW2',
   u'helpful': [0, 1],
   u'overall': 2.0,
   'productid': 7,
   u'reviewText': u"I wish I could give rating for different qualities of the shoes.  I really like the way they look, which I would rate as 5.  But they are not just too small, they are far, far too small.  I measured them sole-to-sole against 3 other pairs of shoes of the same size, and they are not even close to the same length.  I think they are mismarked.  Perhaps they are a 5.5 or a 6.  They had obviously been tried on and returned before I got them.  The packaging and stuffing was neat, but disarranged (stuffing out of the shoes).  Somebody else might have had the same experience with these shoes.  I'll be returning them, too.",
   u'reviewTime': u'03 6, 2014',
   u'reviewerID': u'A2YHF6O2D37PMX',
   u'reviewerName': u'DCP',
   u'summary': u'Far too small',
   u'unixReviewTime': 1394064000},
  {u'asin': u'B00DX9QC2K',
   u'helpful': [2, 3],
   u'overall': 4.0,
   'productid': 10,
   u'reviewText': u"Update 04-09-14:  Upgraded from 3 to 4 stars.  This week I wore them for the first time.  They were very comfortable almost all day at work, especially the toe box, which often is too pointed for me.  After about 7 hours the tiny little places that rubbed prompted me to change shoes, but I really think one more wearing will soften those little places.  Who knows, after two more wearings I may raise the rating to 5 stars.They fit in almost all respects.  They are a tiny bit tight across where the elastic is, but I think they'll stretch.  I'm okay with how they look, and I really like the color.  They aren't as cute on, in my opinion, as they are in the picture, but they are still fine.  It's difficult to summarize.  I guess they are middle-of-the-road.  Nice enough to keep, but not quite as nice as I'd hoped.  I love Clarks and have several pairs of shoes and boots, so I will hope for the best with this pair.  If I could, I'd give 3.5 stars.",
   u'reviewTime': u'03 10, 2014',
   u'reviewerID': u'A2YHF6O2D37PMX',
   u'reviewerName': u'DCP',
   u'summary': u'Nice shoe',
   u'unixReviewTime': 1394409600},
  {u'asin': u'B00DX9SZ7A',
   u'helpful': [0, 0],
   u'overall': 3.0,
   'productid': 11,
   u'reviewText': u"They don't fit badly, and I really like Clarks shoes, but this pair is just not right for my feet.  Also, I think they look better in the photos than in real life.  They look more casual than I expected, with rough edges.",
   u'reviewTime': u'03 3, 2014',
   u'reviewerID': u'A2YHF6O2D37PMX',
   u'reviewerName': u'DCP',
   u'summary': u'Okay, but not for me',
   u'unixReviewTime': 1393804800}],
 2: [{u'asin': u'B002MH3OH0',
   u'helpful': [0, 0],
   u'overall': 5.0,
   'productid': 12,
   u'reviewText': u'My little girl love these shoes, but they are a bit tricky to put on. She can not manage to do that her self, but when they are on they seems really good and comfy. They look really good swell.',
   u'reviewTime': u'10 3, 2013',
   u'reviewerID': u'ASSFVTXVRP2TJ',
   u'reviewerName': u'Soto',
   u'summary': u'super nice shoes',
   u'unixReviewTime': 1380758400},
  {u'asin': u'B004AS1GQU',
   u'helpful': [1, 3],
   u'overall': 5.0,
   'productid': 13,
   u'reviewText': u'Disse buksene er meget fine p, og lillemor elsker de sm hjertene p lommene bak. De kan justeres i livet og sitter bra. Kan  anbefales :-)',
   u'reviewTime': u'11 5, 2012',
   u'reviewerID': u'ASSFVTXVRP2TJ',
   u'reviewerName': u'Soto',
   u'summary': u'Supert',
   u'unixReviewTime': 1352073600},
  {u'asin': u'B004WK8RQS',
   u'helpful': [0, 0],
   u'overall': 5.0,
   'productid': 14,
   u'reviewText': u'My girl loves these slippers, they look good and feels great acording to my 4 year old. I would recomend these.',
   u'reviewTime': u'03 3, 2014',
   u'reviewerID': u'ASSFVTXVRP2TJ',
   u'reviewerName': u'Soto',
   u'summary': u'nice slippers',
   u'unixReviewTime': 1393804800},
  {u'asin': u'B004Z4I4G4',
   u'helpful': [0, 0],
   u'overall': 5.0,
   'productid': 15,
   u'reviewText': u'Disse buksene sitter meget fint p, og de er i et behaglig stoff som gjr det lett for minste jenta  bevege seg nr hun har dem p. Supre Bukser',
   u'reviewTime': u'11 5, 2012',
   u'reviewerID': u'ASSFVTXVRP2TJ',
   u'reviewerName': u'Soto',
   u'summary': u'Kjempe fine bukser',
   u'unixReviewTime': 1352073600},
  {u'asin': u'B007XODRQU',
   u'helpful': [0, 3],
   u'overall': 5.0,
   'productid': 17,
   u'reviewText': u'Disse kjolene/tunikane er kjempe fine p. Har kjpt tre stykker og min lille rver elsker dem. Hun blir super st i dem samtidig som de gir rom for lek og bevegelse. Anbefales.',
   u'reviewTime': u'10 22, 2012',
   u'reviewerID': u'ASSFVTXVRP2TJ',
   u'reviewerName': u'Soto',
   u'summary': u'kjempe ste',
   u'unixReviewTime': 1350864000}]}




Error:

Exception in thread Thread-7:
Traceback (most recent call last):
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "<ipython-input-12-f46eda097bf8>", line 58, in load_image_async
    jpg2=np.uint8(np.asarray(Image.open(StringIO(Item[jjj]['imgs'])).convert('RGB').resize((224,224))))
KeyError: 9

Exception in thread Thread-4:
Traceback (most recent call last):
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "<ipython-input-12-f46eda097bf8>", line 58, in load_image_async
    jpg2=np.uint8(np.asarray(Image.open(StringIO(Item[jjj]['imgs'])).convert('RGB').resize((224,224))))
KeyError: 9

Exception in thread Thread-5:
Traceback (most recent call last):
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "<ipython-input-12-f46eda097bf8>", line 58, in load_image_async
    jpg2=np.uint8(np.asarray(Image.open(StringIO(Item[jjj]['imgs'])).convert('RGB').resize((224,224))))
KeyError: 8

Exception in thread Thread-6:
Traceback (most recent call last):
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/Users/user/anaconda2/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "<ipython-input-12-f46eda097bf8>", line 58, in load_image_async
    jpg2=np.uint8(np.asarray(Image.open(StringIO(Item[jjj]['imgs'])).convert('RGB').resize((224,224))))
KeyError: 8

0 个答案:

没有答案