Skip to content

Instantly share code, notes, and snippets.

@dmitrysarov
Last active May 31, 2020 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitrysarov/1d184a3726e6863fa986e0f6c807c583 to your computer and use it in GitHub Desktop.
Save dmitrysarov/1d184a3726e6863fa986e0f6c807c583 to your computer and use it in GitHub Desktop.

Python hacks

jupyter profiling https://jakevdp.github.io/PythonDataScienceHandbook/01.07-timing-and-profiling.html
line profiler https://github.com/rkern/line_profiler

Jupyter animation

%%capture
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
plt.rcParams["animation.html"] = "jshtml"
import numpy as np

arr = a
fig, ax = plt.subplots(figsize=(10,10))
l = ax.imshow(arr[0], cmap='gray')
def animate(i):
    l.set_data(arr[i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(arr), interval=1/7*1000)

Tensorboard add plot

fig, ax = plt.subplots(1, 2)
ax[0].scatter(list(range(len(test_loader.dataset))), all_y[:, 0].detach().cpu().numpy(), label='target',
              alpha=0.1)
ax[0].scatter(list(range(len(test_loader.dataset))), all_y_pred[:, 0].detach().cpu().numpy(), label='pred',
              alpha=0.1)
ax[0].set_title('angulation')
ax[1].scatter(list(range(len(test_loader.dataset))), all_y[:, 1].detach().cpu().numpy(), label='target',
              alpha=0.1)
ax[1].scatter(list(range(len(test_loader.dataset))), all_y_pred[:, 1].detach().cpu().numpy(), label='pred',
              alpha=0.1)
ax[1].set_title('rotation')
ax[0].set_ylim(0, 1)
ax[1].set_ylim(0, 1)
plt.legend()
writer.add_figure('targer_values', fig, epoch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment