3
Eg @ sf d Z ddlZddlmZmZ dd Zdd ZG dd d eZ e Z
G d
d deZG dd
d
eZdS )a( Functions that could be used to visualize Tensors.
This is adapted from the old-time iceberk package that Yangqing wrote... Oh gold
memories. Before decaf and caffe. Why iceberk? Because I was at Berkeley,
bears are vegetarian, and iceberg lettuce has layers of leaves.
(This joke is so lame.)
N)cmpyplotc C s* | j }| j|d |d j|d |d S )zConvert a HWC array to CHW. )ndimswapaxes)arrr r
C/usr/local/lib64/python3.6/site-packages/caffe2/python/visualize.pyChannelFirst s r c C s* | j }| j|d |d j|d |d S )zConvert a CHW array to HWC.r r r )r r )r r r
r
r ChannelLast s r
c @ sV e Zd ZdZdddZdddZddejfdd Zd
d Z dejfdd
Z
dd ZdS )PatchVisualizerz&PatchVisualizer visualizes patches.
r c C s
|| _ d S )N)gap)selfr r
r
r __init__ s zPatchVisualizer.__init__Nc C sr t |jdkr |j| j|}n$t |jdkrD|jd dkrDtdt |jdkr`|dkr`tj}tj||d |S )zVisualizes one single patch.
The input patch could be a vector (in which case we try to infer the shape
of the patch), a 2-D matrix, or a 3-D matrix whose 3rd dimension has 3
channels.
r r r z$The input patch shape isn't correct.N)cmap) lenshapereshapeget_patch_shape
ValueErrorr grayr imshow)r patchr r
r
r
ShowSingle# s zPatchVisualizer.ShowSinglec C s |j d }|dkr&ttjtj|}ttj|t| }t|j dkrj|j|j d f| j|d }tj |j dd | j
}|tj ||g | j
}t|j dkr|j d dkr|j|j dd }t|} |dkrtj
}n&|j d dkrt|d } ntdnt|} |dkr&tj
}tj| || }
x^t|D ]R}|| |d }|| |d }
|| |
|||j d |
|
|j d f<