Skip to content

Instantly share code, notes, and snippets.

View khakhlyuk's full-sized avatar

Alex Khakhlyuk khakhlyuk

  • Databricks
  • Berlin
  • 09:05 (UTC +01:00)
  • LinkedIn in/khakhlyuk
View GitHub Profile
@khakhlyuk
khakhlyuk / import_drive.py
Created December 30, 2019 21:04
Importing drive in Google Colab
from google.colab import drive
drive.mount('/drive')
%cd '/drive/My Drive/thesis/fixedconv/'
planes = 3
k_2d = np.zeros((5,5))
k_3d = k_2d * np.array([1] * planes).reshape(planes, 1, 1)
@khakhlyuk
khakhlyuk / lambda_layer.py
Created December 6, 2019 16:10
Lambda Layer Pytorch
class Lambda(nn.Module):
def __init__(self, func):
super().__init__()
self.func = func
def forward(self, x):
return self.func(x)
# use
Lambda(lambda x: x.view(x.size(0), -1))
@khakhlyuk
khakhlyuk / pytorch_tensor_size.py
Created November 17, 2019 20:44
Memory size of a pytorch tensor
x.element_size() * x.nelement()
import gc
del file_to_be_deleted
gc.collect()
@khakhlyuk
khakhlyuk / py-spy.bash
Last active November 17, 2019 20:15
py-spy python profiling
sudo py-spy record -r 100 -d 30 -o profile.svg -- python file.py
sudo py-spy top -r 100 -- python file.py