| import matplotlib.pyplot as plt | |
| import time, sys, math | |
| import numpy as np | |
| def stream(string, variables) : | |
| sys.stdout.write(f'\r{string}' % variables) | |
| def num_params(model) : | |
| parameters = filter(lambda p: p.requires_grad, model.parameters()) | |
| parameters = sum([np.prod(p.size()) for p in parameters]) / 1_000_000 | |
| print('Trainable Parameters: %.3f million' % parameters) | |
| def time_since(started) : | |
| elapsed = time.time() - started | |
| m = int(elapsed // 60) | |
| s = int(elapsed % 60) | |
| if m >= 60 : | |
| h = int(m // 60) | |
| m = m % 60 | |
| return f'{h}h {m}m {s}s' | |
| else : | |
| return f'{m}m {s}s' | |
| def plot(array) : | |
| fig = plt.figure(figsize=(30, 5)) | |
| ax = fig.add_subplot(111) | |
| ax.xaxis.label.set_color('grey') | |
| ax.yaxis.label.set_color('grey') | |
| ax.xaxis.label.set_fontsize(23) | |
| ax.yaxis.label.set_fontsize(23) | |
| ax.tick_params(axis='x', colors='grey', labelsize=23) | |
| ax.tick_params(axis='y', colors='grey', labelsize=23) | |
| plt.plot(array) | |
| def plot_spec(M) : | |
| M = np.flip(M, axis=0) | |
| plt.figure(figsize=(18,4)) | |
| plt.imshow(M, interpolation='nearest', aspect='auto') | |
| plt.show() | |