イメージ
2 minute read
W&B に画像をログするためのフォーマット。
Image(
data_or_path: "ImageDataOrPathType",
mode: Optional[str] = None,
caption: Optional[str] = None,
grouping: Optional[int] = None,
classes: Optional[Union['Classes', Sequence[dict]]] = None,
boxes: Optional[Union[Dict[str, 'BoundingBoxes2D'], Dict[str, dict]]] = None,
masks: Optional[Union[Dict[str, 'ImageMask'], Dict[str, dict]]] = None,
file_type: Optional[str] = None
) -> None
Args | |
---|---|
data_or_path |
(numpy array, string, io) 画像データの numpy 配列または PIL 画像を受け付けます。クラスはデータフォーマットを推測して変換します。 |
mode |
(string) 画像のための PIL モード。最も一般的なのは “L”, “RGB”, “RGBA” です。詳しくは https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes を参照してください。 |
caption |
(string) 画像表示用のラベル。 |
注意 : wandb.Image
として torch.Tensor
をログする際、画像は正規化されます。画像を正規化したくない場合は、テンソルを PIL Image に変換してください。
例:
numpy 配列から wandb.Image を作成
import numpy as np
import wandb
with wandb.init() as run:
examples = []
for i in range(3):
pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
image = wandb.Image(pixels, caption=f"random field {i}")
examples.append(image)
run.log({"examples": examples})
PILImage から wandb.Image を作成
import numpy as np
from PIL import Image as PILImage
import wandb
with wandb.init() as run:
examples = []
for i in range(3):
pixels = np.random.randint(
low=0, high=256, size=(100, 100, 3), dtype=np.uint8
)
pil_image = PILImage.fromarray(pixels, mode="RGB")
image = wandb.Image(pil_image, caption=f"random field {i}")
examples.append(image)
run.log({"examples": examples})
.png (デフォルト) ではなく .jpg をログ
import numpy as np
import wandb
with wandb.init() as run:
examples = []
for i in range(3):
pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
image = wandb.Image(pixels, caption=f"random field {i}", file_type="jpg")
examples.append(image)
run.log({"examples": examples})
Attributes |
---|
メソッド
all_boxes
@classmethod
all_boxes(
images: Sequence['Image'],
run: "LocalRun",
run_key: str,
step: Union[int, str]
) -> Union[List[Optional[dict]], bool]
all_captions
@classmethod
all_captions(
images: Sequence['Media']
) -> Union[bool, Sequence[Optional[str]]]
all_masks
@classmethod
all_masks(
images: Sequence['Image'],
run: "LocalRun",
run_key: str,
step: Union[int, str]
) -> Union[List[Optional[dict]], bool]
guess_mode
guess_mode(
data: "np.ndarray"
) -> str
np.array が表している画像の種類を推測します。
to_uint8
@classmethod
to_uint8(
data: "np.ndarray"
) -> "np.ndarray"
画像データを uint8 に変換します。
範囲 [0,1] の浮動小数点画像と範囲 [0,255] の整数画像を必要に応じてクリッピングして uint8 に変換します。
クラス変数 | |
---|---|
MAX_DIMENSION |
65500 |
MAX_ITEMS |
108 |
フィードバック
このページは役に立ちましたか?
Glad to hear it! If you have further feedback, please let us know.
Sorry to hear that. Please tell us how we can improve.