import matplotlib.pyplot as plt
import matplotlib.patches as patches
%matplotlib inline
Visualisation
Interactive tutorial on visualisation with practical implementations and visualizations
= 0.5, 0.5
someX, someY = plt.subplots()
fig,ax "equal")
ax.set_aspect(0.5, 0.5), 0.1, 0.1,
ax.add_patch(patches.Rectangle((=1, facecolor='gray')) alpha
import sys
"convnet-drawer/") sys.path.append(
from convnet_drawer import Model, Conv2D, MaxPooling2D, Flatten, Dense
from matplotlib_util import save_model_to_file
= 1/5
channel_scale
= Model(input_shape=(32, 32, 1))
model 6, (3, 3), (1, 1)))
model.add(Conv2D(3, 3), strides=(2, 2)))
model.add(MaxPooling2D((256, (5, 5), padding="same"))
model.add(Conv2D(3, 3), strides=(2, 2)))
model.add(MaxPooling2D((384, (3, 3), padding="same"))
model.add(Conv2D(384, (3, 3), padding="same"))
model.add(Conv2D(256, (3, 3), padding="same"))
model.add(Conv2D(3, 3), strides=(2, 2)))
model.add(MaxPooling2D((
model.add(Flatten())4096))
model.add(Dense(4096))
model.add(Dense(1000))
model.add(Dense(
# save as svg file
"example.svg")
model.save_fig(
# save via matplotlib
"example.pdf") save_model_to_file(model,
model
##### from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
def cuboid_data(o, size=(1,1,1)):
# code taken from
# https://stackoverflow.com/a/35978146/4124317
# suppose axis direction: x: to left; y: to inside; z: to upper
# get the length, width, and height
= size
l, w, h = [[o[0], o[0] + l, o[0] + l, o[0], o[0]],
x 0], o[0] + l, o[0] + l, o[0], o[0]],
[o[0], o[0] + l, o[0] + l, o[0], o[0]],
[o[0], o[0] + l, o[0] + l, o[0], o[0]]]
[o[= [[o[1], o[1], o[1] + w, o[1] + w, o[1]],
y 1], o[1], o[1] + w, o[1] + w, o[1]],
[o[1], o[1], o[1], o[1], o[1]],
[o[1] + w, o[1] + w, o[1] + w, o[1] + w, o[1] + w]]
[o[= [[o[2], o[2], o[2], o[2], o[2]],
z 2] + h, o[2] + h, o[2] + h, o[2] + h, o[2] + h],
[o[2], o[2], o[2] + h, o[2] + h, o[2]],
[o[2], o[2], o[2] + h, o[2] + h, o[2]]]
[o[return np.array(x), np.array(y), np.array(z)
def plotCubeAt(pos=(0,0,0), size=(1,1,1), ax=None,**kwargs):
# Plotting a cube element at position pos
if ax !=None:
= cuboid_data( pos, size )
X, Y, Z =1, cstride=1, **kwargs)
ax.plot_surface(X, Y, Z, rstride
= [(32,32,1), (28, 28, 6), (14, 14, 6), (10, 10, 16), (5, 5, 16), (1, 120, 1)]
sizes = [(0, 0, 0)]*len(sizes)
positions for i in range(1, len(sizes)):
= (positions[i-1][0] + sizes[i-1][0]+10, 0, 0)
positions[i] = ["grey"]*len(sizes)
colors
= plt.figure()
fig = fig.gca(projection='3d')
ax 84, -90)
ax.view_init('equal')
ax.set_aspect(
ax.set_axis_off()'X')
ax.set_xlabel(-5, positions[-1][0]+10)
ax.set_xlim('Y')
ax.set_ylabel(-1, 130)
ax.set_ylim('Z')
ax.set_zlabel(-1, 5)
ax.set_zlim(#ax.set_visible(False)
for p,s,c in zip(positions,sizes,colors):
=p, size=s, ax=ax, color=c)
plotCubeAt(pos0.)
ax.w_zaxis.line.set_lw(
ax.set_zticks([])
for i in range(len(positions)):
0], -5, 0, "X".join(str(x) for x in sizes[i]), color='black', fontsize=4)
ax.text(positions[i][=0, right=1, bottom=0, top=1)
fig.subplots_adjust(left
fig.tight_layout()
plt.tight_layout()"lenet.pdf", bbox_inches="tight", transparent=True, dpi=600) plt.savefig(