Il est aujourd'hui assez facile de construire une boîte englobante autour d'un visage dans une image. Le deep learning permet d'extraire précisément les pixels du visage.
from jyquickhelper import add_notebook_menu
add_notebook_menu()
%matplotlib inline
from code_beatrix.ai import DLImageSegmentation
model = DLImageSegmentation(fLOG=print)
[DLImageSegmentation] download model 'FCN8s' [DLImageSegmentation] [C:\Users\xavie/data/models/chainer/fcn8s_from_caffe.npz] Checking md5 (256c2a8235c1c65e62e48d3284fbd384) [DLImageSegmentation] load_npz 'C:\Users\xavie/data/models/chainer/fcn8s_from_caffe.npz' [DLImageSegmentation] class_name '['background' 'aeroplane' 'bicycle' 'bird' 'boat' 'bottle' 'bus' 'car' 'cat' 'chair' 'cow' 'diningtable' 'dog' 'horse' 'motorbike' 'person' 'potted plant' 'sheep' 'sofa' 'train' 'tv/monitor']' [DLImageSegmentation] cpu
img = 'images/Tesla_circa_1890c.jpg'
feat, pred = model.predict(img)
pred.shape
(295, 220)
viz = model.plot(img, pred) # img ou feat
c:\Python363_x64\lib\site-packages\skimage\transform\_warps.py:84: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15. warn("The default mode, 'constant', will be changed to 'reflect' in "
import skimage.io as skio
skio.imshow(viz)
<matplotlib.image.AxesImage at 0x18000a1a8d0>
from PIL import Image
img = 'images/Tesla_circa_1890c.jpg'
pilimg = Image.open(img)
si = pilimg.size
pilimg2 = pilimg.resize((si[0]//2, si[1]//2))
from skimage.io._plugins.pil_plugin import pil_to_ndarray
skimg = pil_to_ndarray(pilimg2)
skimg.shape
(147, 110, 3)
feat, pred = model.predict(skimg)
pred.shape
(147, 110)
viz = model.plot(skimg, pred)
c:\Python363_x64\lib\site-packages\skimage\transform\_warps.py:84: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15. warn("The default mode, 'constant', will be changed to 'reflect' in "
skio.imshow(viz)
<matplotlib.image.AxesImage at 0x18001a8bd68>
img = 'images/h2015_2.jpg'
pilimg = Image.open(img)
si = pilimg.size
pilimg2 = pilimg.resize((si[0]//2, si[1]//2))
skimg = pil_to_ndarray(pilimg2)
skimg.shape
(456, 684, 3)
skio.imshow(skimg)
<matplotlib.image.AxesImage at 0x1800210b9e8>
feat, pred = model.predict(skimg)
pred.shape
(456, 684)
viz = model.plot(feat, pred)
c:\Python363_x64\lib\site-packages\skimage\transform\_warps.py:84: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15. warn("The default mode, 'constant', will be changed to 'reflect' in "
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(14, 12))
ax.imshow(viz)
<matplotlib.image.AxesImage at 0x1800216b9e8>