jupyter lab上で画像のラベリングをする
5330 ワード
やりたいこと
AIに使いたい画像のラベリングをしたいが、GUIを作るのが面倒。。。と思い、
JupyterLab上でできないかーと考え、色々調べてたらできたのでそのときのメモ。
matplotで表示した画像を更新しながらinputでラベリングを入力するようなイメージ。
実行環境
- Python 3.8.5
- jupyter lab 2.2.2
- mac(windows10でも実行済み)
コード
sample_imgフォルダにある画像をラベリングする。
準備
import cv2
import matplotlib.pyplot as plt
import os
import glob
import IPython
# 画像のpathを取得
img_list = glob.glob(os.path.join(r"sample_img","*.jpg"))
img_list
>>> ['sample_img/img3.jpg', 'sample_img/img2.jpg', 'sample_img/img1.jpg']
画像を表示するコード
name_list = []
for img_path in img_list:
# 画像の読み込み
img = cv2.imread(img_path)
# 画像を表示するフレーム
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
ax.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.title(img_path)
plt.pause(.01)
# ラベル付けするためのテキストボックス
comment = input()
if comment == "break":
break
else:
# 表示している画像をクリア
IPython.display.clear_output()
# Inputに入力した文字列をリストに追加
name_list.append(comment)
確認
# name_listの確認
name_list
>>> ['dog', 'cat', 'cat']
最後に
Input部分をラジオボタンみたいにできたらいいな〜.
Author And Source
この問題について(jupyter lab上で画像のラベリングをする), 我々は、より多くの情報をここで見つけました https://qiita.com/andyCandy/items/b371aa9a48d5245f23a2著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .