다운로드
작성자: admin 작성일시: 2018-04-18 21:32:19 조회수: 528 다운로드: 79
카테고리: 머신 러닝 태그목록:

VGG16

In [2]:
from keras.applications.vgg16 import VGG16, decode_predictions
In [3]:
%%time
model = VGG16()
Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5
553467904/553467096 [==============================] - 1326s 2us/step
CPU times: user 28.4 s, sys: 37.6 s, total: 1min 6s
Wall time: 22min 13s
In [4]:
model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 224, 224, 3)       0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 224, 224, 64)      1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 224, 224, 64)      36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 112, 112, 64)      0         
_________________________________________________________________
block2_conv1 (Conv2D)        (None, 112, 112, 128)     73856     
_________________________________________________________________
block2_conv2 (Conv2D)        (None, 112, 112, 128)     147584    
_________________________________________________________________
block2_pool (MaxPooling2D)   (None, 56, 56, 128)       0         
_________________________________________________________________
block3_conv1 (Conv2D)        (None, 56, 56, 256)       295168    
_________________________________________________________________
block3_conv2 (Conv2D)        (None, 56, 56, 256)       590080    
_________________________________________________________________
block3_conv3 (Conv2D)        (None, 56, 56, 256)       590080    
_________________________________________________________________
block3_pool (MaxPooling2D)   (None, 28, 28, 256)       0         
_________________________________________________________________
block4_conv1 (Conv2D)        (None, 28, 28, 512)       1180160   
_________________________________________________________________
block4_conv2 (Conv2D)        (None, 28, 28, 512)       2359808   
_________________________________________________________________
block4_conv3 (Conv2D)        (None, 28, 28, 512)       2359808   
_________________________________________________________________
block4_pool (MaxPooling2D)   (None, 14, 14, 512)       0         
_________________________________________________________________
block5_conv1 (Conv2D)        (None, 14, 14, 512)       2359808   
_________________________________________________________________
block5_conv2 (Conv2D)        (None, 14, 14, 512)       2359808   
_________________________________________________________________
block5_conv3 (Conv2D)        (None, 14, 14, 512)       2359808   
_________________________________________________________________
block5_pool (MaxPooling2D)   (None, 7, 7, 512)         0         
_________________________________________________________________
flatten (Flatten)            (None, 25088)             0         
_________________________________________________________________
fc1 (Dense)                  (None, 4096)              102764544 
_________________________________________________________________
fc2 (Dense)                  (None, 4096)              16781312  
_________________________________________________________________
predictions (Dense)          (None, 1000)              4097000   
=================================================================
Total params: 138,357,544
Trainable params: 138,357,544
Non-trainable params: 0
_________________________________________________________________
In [5]:
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot

SVG(model_to_dot(model, show_shapes=True).create(prog='dot', format='svg'))
Out:
G 140587035804280 input_1: InputLayer input: output: (None, 224, 224, 3) (None, 224, 224, 3) 140587035805288 block1_conv1: Conv2D input: output: (None, 224, 224, 3) (None, 224, 224, 64) 140587035804280->140587035805288 140587035804784 block1_conv2: Conv2D input: output: (None, 224, 224, 64) (None, 224, 224, 64) 140587035805288->140587035804784 140587035806800 block1_pool: MaxPooling2D input: output: (None, 224, 224, 64) (None, 112, 112, 64) 140587035804784->140587035806800 140587027057856 block2_conv1: Conv2D input: output: (None, 112, 112, 64) (None, 112, 112, 128) 140587035806800->140587027057856 140587027182424 block2_conv2: Conv2D input: output: (None, 112, 112, 128) (None, 112, 112, 128) 140587027057856->140587027182424 140587026726640 block2_pool: MaxPooling2D input: output: (None, 112, 112, 128) (None, 56, 56, 128) 140587027182424->140587026726640 140587026892784 block3_conv1: Conv2D input: output: (None, 56, 56, 128) (None, 56, 56, 256) 140587026726640->140587026892784 140587026463992 block3_conv2: Conv2D input: output: (None, 56, 56, 256) (None, 56, 56, 256) 140587026892784->140587026463992 140587026558928 block3_conv3: Conv2D input: output: (None, 56, 56, 256) (None, 56, 56, 256) 140587026463992->140587026558928 140587026648368 block3_pool: MaxPooling2D input: output: (None, 56, 56, 256) (None, 28, 28, 256) 140587026558928->140587026648368 140587026257960 block4_conv1: Conv2D input: output: (None, 28, 28, 256) (None, 28, 28, 512) 140587026648368->140587026257960 140587026364008 block4_conv2: Conv2D input: output: (None, 28, 28, 512) (None, 28, 28, 512) 140587026257960->140587026364008 140587025925736 block4_conv3: Conv2D input: output: (None, 28, 28, 512) (None, 28, 28, 512) 140587026364008->140587025925736 140587026009896 block4_pool: MaxPooling2D input: output: (None, 28, 28, 512) (None, 14, 14, 512) 140587025925736->140587026009896 140587026159936 block5_conv1: Conv2D input: output: (None, 14, 14, 512) (None, 14, 14, 512) 140587026009896->140587026159936 140587025741920 block5_conv2: Conv2D input: output: (None, 14, 14, 512) (None, 14, 14, 512) 140587026159936->140587025741920 140587025829504 block5_conv3: Conv2D input: output: (None, 14, 14, 512) (None, 14, 14, 512) 140587025741920->140587025829504 140587025387304 block5_pool: MaxPooling2D input: output: (None, 14, 14, 512) (None, 7, 7, 512) 140587025829504->140587025387304 140587025558104 flatten: Flatten input: output: (None, 7, 7, 512) (None, 25088) 140587025387304->140587025558104 140587025636488 fc1: Dense input: output: (None, 25088) (None, 4096) 140587025558104->140587025636488 140587025290800 fc2: Dense input: output: (None, 4096) (None, 4096) 140587025636488->140587025290800 140587025292200 predictions: Dense input: output: (None, 4096) (None, 1000) 140587025290800->140587025292200
In [6]:
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=["accuracy"])
In [7]:
from PIL import Image
 
im = np.array(Image.open('bird1.jpg').resize((224, 224)))
plt.imshow(im)
plt.grid(False)

Prediction

In [9]:
x = im[np.newaxis, :, :, :]
yhat = model.predict(x)
np.argmax(yhat)
Out:
14
In [11]:
label = decode_predictions(yhat)
label = label[0][0]
print('%s (%.2f%%)' % (label[1], label[2]*100))
indigo_bunting (99.99%)

질문/덧글

아직 질문이나 덧글이 없습니다. 첫번째 글을 남겨주세요!