閉じる

データセット内の画像をひとまず見てみるためのコマンド[Kaggle]

www.kaggle.com

import os
import numpy as np
import pandas as pd
from PIL import Image
import matplotlib.pyplot as plt
labels = pd.read_csv('../input/train_labels.csv')
fig = plt.figure(figsize=(25, 4))
# display 20 images
train_imgs = os.listdir("../input/train")
for idx, img in enumerate(np.random.choice(train_imgs, 20)):
ax = fig.add_subplot(2, 20//2, idx+1, xticks=[], yticks=[])
im = Image.open("../input/train/" + img)
plt.imshow(im)
lab = labels.loc[labels['id'] == img.split('.')[0], 'label'].values[0]
ax.set_title(f'Label: {lab}')

f:id:Vastee:20190210134504p:plain


www.kaggle.com

import os
import numpy as np
import pandas as pd
from PIL import Image
import matplotlib.pyplot as plt
labels = pd.read_csv('../input/train.csv')
fig = plt.figure(figsize=(25, 4))
# display 20 images
train_imgs = os.listdir("../input/train")
for idx, img in enumerate(np.random.choice(train_imgs, 20)):
ax = fig.add_subplot(2, 20//2, idx+1, xticks=[], yticks=[])
im = Image.open("../input/train/" + img)
plt.imshow(im)
lab = labels.loc[labels['Image'] == img, 'Id'].values[0]
ax.set_title(f'Label: {lab}')

f:id:Vastee:20190210134509p:plain

入力画像とラベルのパス,およびラベルの整形方法を考えれば基本的にどのデータセットでも適用可能.

Pocket

コメントを残す

あなたのメールアドレスは公開されません。必須項目には印がついています *

© 2020 CV・NLP TIPS | WordPress Theme: Annina Free by CrestaProject.