jupyter notebook 中图像的交互式标注
Interactive labeling of images in jupyter notebook
我有一张图片列表:
pictures = {im1,im2,im3,im4,im5,im6}
哪里
im1:
im2:
im3:
im4:
im5:
im6:
我想给图片分配标签(1,2,3,4 等)
比如这里图片1到3属于标签1,图片4属于标签2,图片5属于标签3,图片6属于标签4。
-> label = {1,1,1,2,3,4}
由于我在标记图像时需要查看图像,因此我需要一种在标记图像时执行此操作的方法。我正在考虑创建一组图像:
然后我通过单击属于相同标签的第一张和最后一张图片来定义范围,例如:
你怎么看?这有可能吗?
我想给不同范围的图片分配不同的标签。
例如:当一个人完成第一个标签的选择时,可以用Double-click表示,然后选择第二个标签范围,然后Double-click,然后做第三个标签范围的选择,然后Double-click,然后做第四个标签的选择射程等
不必 Double-click 更改标签的选择,它也可以只是一个按钮或您可能有的任何其他想法。
最后应该有标签列表。
本质上,您正在寻找的大部分交互都归结为能够显示图像并实时检测对它们的点击。在这种情况下,您可以使用 jupyter widgets(又名 ipywidgets
)模块来实现大部分(如果不是全部)您正在寻找的东西。
查看 here with explanation on how to register to its click event. The problem - we can't display an image on a button, and I didn't find any way to do this within the ipywidgets
documentation. There is an image 小部件描述的按钮小部件,但它不提供 on_click
事件。因此构建一个自定义布局,在每个图像下方都有一个按钮:
COLS = 4
ROWS = 2
IMAGES = ...
IMG_WIDTH = 200
IMG_HEIGHT = 200
def on_click(index):
print('Image %d clicked' % index)
import ipywidgets as widgets
import functools
rows = []
for row in range(ROWS):
cols = []
for col in range(COLS):
index = row * COLS + col
image = widgets.Image(
value=IMAGES[index], width=IMG_WIDTH, height=IMG_HEIGHT
)
button = widgets.Button(description='Image %d' % index)
# Bind the click event to the on_click function, with our index as argument
button.on_click(functools.partial(on_click, index))
# Create a vertical layout box, image above the button
box = widgets.VBox([image, button])
cols.append(box)
# Create a horizontal layout box, grouping all the columns together
rows.append(widgets.HBox(cols))
# Create a vertical layout box, grouping all the rows together
result = widgets.VBox(rows)
从技术上讲,您还可以编写自定义小部件来显示图像并监听点击,但我认为这不值得您花费时间和精力。
祝你好运!
qsl 包提供了执行此操作的小部件。对于您的情况,以下代码将允许您批量标记图像。完全披露,qsl
是我开始的一个项目,因为我和你一样,想在 Jupyter 笔记本中标记图像。
import qsl
from IPython.display import display
labeler = qsl.MediaLabeler(
items=[
{"target": "https://i.stack.imgur.com/cML6z.jpg"},
{"target": "https://i.stack.imgur.com/6EVAP.jpg"},
{"target": "https://i.stack.imgur.com/CAxUw.jpg"},
{"target": "https://i.stack.imgur.com/8fhan.jpg"},
{"target": "https://i.stack.imgur.com/eMXn5.jpg"},
{"target": "https://i.stack.imgur.com/YFBfM.jpg"}
],
# Optional, you can also configure the labeler from
# the UI.
config={
"image": [
{
"name": "Type",
"options": [
{"name": "Foo"},
{"name": "Bar"}
]
}
]
},
# Optional, set to 1 if you want to label
# one image at a time.
batch_size=4,
# Optionally, save labels to JSON. You
# can also get the labels using `labeler.items`.
jsonpath="labels.json"
)
display(labeler)
这会生成如下所示的 UI。
这里有一个 Google Colab notebook 展示了如何在 Google Colab 中执行此操作。
我有一张图片列表:
pictures = {im1,im2,im3,im4,im5,im6}
哪里
im1:
im2:
im3:
im4:
im5:
im6:
我想给图片分配标签(1,2,3,4 等)
比如这里图片1到3属于标签1,图片4属于标签2,图片5属于标签3,图片6属于标签4。
-> label = {1,1,1,2,3,4}
由于我在标记图像时需要查看图像,因此我需要一种在标记图像时执行此操作的方法。我正在考虑创建一组图像:
然后我通过单击属于相同标签的第一张和最后一张图片来定义范围,例如:
你怎么看?这有可能吗?
我想给不同范围的图片分配不同的标签。
例如:当一个人完成第一个标签的选择时,可以用Double-click表示,然后选择第二个标签范围,然后Double-click,然后做第三个标签范围的选择,然后Double-click,然后做第四个标签的选择射程等
不必 Double-click 更改标签的选择,它也可以只是一个按钮或您可能有的任何其他想法。
最后应该有标签列表。
本质上,您正在寻找的大部分交互都归结为能够显示图像并实时检测对它们的点击。在这种情况下,您可以使用 jupyter widgets(又名 ipywidgets
)模块来实现大部分(如果不是全部)您正在寻找的东西。
查看 here with explanation on how to register to its click event. The problem - we can't display an image on a button, and I didn't find any way to do this within the ipywidgets
documentation. There is an image 小部件描述的按钮小部件,但它不提供 on_click
事件。因此构建一个自定义布局,在每个图像下方都有一个按钮:
COLS = 4
ROWS = 2
IMAGES = ...
IMG_WIDTH = 200
IMG_HEIGHT = 200
def on_click(index):
print('Image %d clicked' % index)
import ipywidgets as widgets
import functools
rows = []
for row in range(ROWS):
cols = []
for col in range(COLS):
index = row * COLS + col
image = widgets.Image(
value=IMAGES[index], width=IMG_WIDTH, height=IMG_HEIGHT
)
button = widgets.Button(description='Image %d' % index)
# Bind the click event to the on_click function, with our index as argument
button.on_click(functools.partial(on_click, index))
# Create a vertical layout box, image above the button
box = widgets.VBox([image, button])
cols.append(box)
# Create a horizontal layout box, grouping all the columns together
rows.append(widgets.HBox(cols))
# Create a vertical layout box, grouping all the rows together
result = widgets.VBox(rows)
从技术上讲,您还可以编写自定义小部件来显示图像并监听点击,但我认为这不值得您花费时间和精力。
祝你好运!
qsl 包提供了执行此操作的小部件。对于您的情况,以下代码将允许您批量标记图像。完全披露,qsl
是我开始的一个项目,因为我和你一样,想在 Jupyter 笔记本中标记图像。
import qsl
from IPython.display import display
labeler = qsl.MediaLabeler(
items=[
{"target": "https://i.stack.imgur.com/cML6z.jpg"},
{"target": "https://i.stack.imgur.com/6EVAP.jpg"},
{"target": "https://i.stack.imgur.com/CAxUw.jpg"},
{"target": "https://i.stack.imgur.com/8fhan.jpg"},
{"target": "https://i.stack.imgur.com/eMXn5.jpg"},
{"target": "https://i.stack.imgur.com/YFBfM.jpg"}
],
# Optional, you can also configure the labeler from
# the UI.
config={
"image": [
{
"name": "Type",
"options": [
{"name": "Foo"},
{"name": "Bar"}
]
}
]
},
# Optional, set to 1 if you want to label
# one image at a time.
batch_size=4,
# Optionally, save labels to JSON. You
# can also get the labels using `labeler.items`.
jsonpath="labels.json"
)
display(labeler)
这会生成如下所示的 UI。
这里有一个 Google Colab notebook 展示了如何在 Google Colab 中执行此操作。