<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 看一下 imagenet 的分類
Step2:  Imagenet 2012 網頁
http
<ASSISTANT_TASK:>
Python Code:
from keras.applications import imagenet_utils
imagenet_utils.CLASS_INDEX_PATH
from urllib.request import urlopen
import json
with urlopen(imagenet_utils.CLASS_INDEX_PATH) as jsonf:
    data = jsonf.read()
class_dict = json.loads(data.decode())
[class_dict[str(i)][1] for i in range(1000)]
Explanation: 看一下 imagenet 的分類
End of explanation
# 下載 圖片
import os
import urllib
from urllib.request import urlretrieve
dataset = 'ILSVRC2012_val_1000.tar'
def reporthook(a,b,c):
    print("\rdownloading: %5.1f%%"%(a*b*100.0/c), end="")
    
if not os.path.isfile(dataset):
        origin = "https://www.dropbox.com/s/vippynksgd8c6qt/ILSVRC2012_val_1000.tar?dl=1"
        print('Downloading data from %s' % origin)
        urlretrieve(origin, dataset, reporthook=reporthook)
# 解開圖片
from tarfile import TarFile
tar = TarFile(dataset)
tar.extractall()
# 讀取圖片
from PIL import Image as pimage
from glob import glob
imgs = []
files = list(glob('ILSVRC2012_img_val/ILSVRC2012_val_*.JPEG'))
for fn in files:
    img = pimage.open(fn)
    if img.mode != 'RGB':
        img = img.convert('RGB')
    img = np.array(img.resize((224,224)))    
    imgs.append(img)
imgs = np.array(imgs)
# 準備資料，轉成通用的格式(扣掉顏色的中間值)
p_imgs = imagenet_utils.preprocess_input(np.float32(imgs))
del imgs
# 實際
predictions = pretrained.predict(p_imgs)
# 對應編碼
results = imagenet_utils.decode_predictions(predictions)
from IPython.display import Image, HTML, display
for fn, res in zip(files[:100], results[:100]):
    res_text = "".join("<li>{:05.2f}% : {}</li>".format(x[2]*100, x[1]) for x in res)
    display(HTML(
    <table><tr>
    <td><img width=200 src="{}" /></td>
    <td><ul>{}</ul></td>
    </tr>
    </table>
    .format(fn, res_text)))    
Explanation: Imagenet 2012 網頁
http://image-net.org/challenges/LSVRC/2012/signup
資料下載
http://academictorrents.com/browse.php?search=imagenet
一千張圖片
https://www.dropbox.com/s/vippynksgd8c6qt/ILSVRC2012_val_1000.tar?dl=0
End of explanation
<END_TASK>