Visuals
- class todd.visuals.BaseVisual[source]
Bases:
ABC- activation(activation, left=0, top=0, width=None, height=None, opacity=0.5)[source]
Draw the activation map.
Suppose our activation map is \((256, 13, 20)\), where 256 is the number of channels, 13 is the height, and 20 is the width:
>>> activation = torch.rand(256, 13, 20)
We first reduce the channel dimension, using whatever reduction:
>>> import einops >>> activation = einops.reduce( ... activation, ... 'c h w -> h w', ... reduction='mean', ... )
Then we draw the activation map:
>>> from .pptx import PPTXVisual >>> visual = PPTXVisual(640, 426) >>> visual.activation( ... activation, ... width=visual.width, ... height=visual.height, ... ) <pptx.shapes.picture.Picture object at ...>
- Parameters:
activation (Tensor) – \((H, W)\)
left (int) – x coordinate of the left side of the activation map
top (int) – y coordinate of the top size of the activation map
width (int | None) – width of the activation map
height (int | None) – height of the activation map
opacity (float) – opacity of the activation map
- Return type:
- abstractmethod rectangle(left, top, width, height, color=RGB(0.0, 0.0, 0.0), thickness=1, fill=None)[source]
- class todd.visuals.CV2Visual[source]
Bases:
BaseVisual
- class todd.visuals.PPTXVisual[source]
Bases:
BaseVisualVisualize data in the format of PowerPoint.
The PowerPoint contains only one slide. For more details, refer to python-pptx.
- __init__(width, height, **kwargs)[source]
Initialize the PowerPoint with a single slide.
To initialize a PowerPoint with width 640pt and height 426pt, use the following code:
>>> visual = PPTXVisual(640, 426)
Once initialized, the width and height of the slide cannot be altered. We can read the width and height of the PowerPoint by:
>>> visual.width 640 >>> visual.height 426
- image(image, left=0, top=0, width=None, height=None, opacity=1.0)[source]
Add an image to the PowerPoint.
Suppose the image is \((426, 640)\):
>>> image = np.random.randint(0, 256, (426, 640, 3))
In most cases, the PowerPoint is of the same size as the image, so that the image covers the whole background:
>>> h, w, _ = image.shape >>> visual = PPTXVisual(w, h) >>> visual.image(image) <pptx.shapes.picture.Picture object at ...>
The returned
pptx.shapes.picture.Pictureobject can be used to fine-tune the properties of the image. Note that the DPI of the image should not be changed thoughtlessly, because of the bizarre measurements in PowerPoint. The most common measurement unit in PowerPoint is Point (pt), where 1pt equals 1/72 inches. However, images are measured in pixels and 1 pixel equals 1/DPI inches. By default, DPI is 72 so that 1 pixel is 1pt. When DPI is set to other values, the size of the image may become larger or smaller than it is supposed to be.- Parameters:
- Return type:
- property presentation: Presentation
- save(path)[source]
Save the PowerPoint.
The save target can either be a filepath, for example:
>>> import tempfile >>> with tempfile.NamedTemporaryFile() as f: ... PPTXVisual(640, 426).save(f.name)
Or it can simply be a file-like object:
>>> with tempfile.TemporaryFile() as f: ... PPTXVisual(640, 426).save(f)
- Parameters:
path (Any) – destination path
- Return type:
None
- property shapes: SlideShapes