This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class dotaccess(dict): | |
__getattr__ = dict.get | |
__setattr__ = dict.__setitem__ | |
__delattr__ = dict.__delitem__ | |
ml_eng = { | |
'name': 'Diogo Santiago', | |
'link': 'http://github.com/dsantiago/' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KerasProgressBar(pl.callbacks.progress.ProgressBarBase): | |
def on_train_start(self, trainer, pl_module): | |
super().on_train_start(trainer, pl_module) | |
pbar = tf.keras.utils.Progbar(trainer.num_training_batches) | |
self.keras_bar = pbar | |
def on_train_epoch_start(self, trainer, pl_module): | |
super().on_train_epoch_start(trainer, pl_module) | |
print(f'Epoch {trainer.current_epoch+1}/{trainer.max_epochs}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import torch | |
crit = torch.nn.BCELoss() | |
preds = torch.tensor([[1, 0.2, 0.3, 1, 1], [1, 0.1, 0.7, 1, 1]]).float() # n classes | |
targets = torch.tensor([[1, 1, 1, 0, 0], [1, 0, 1, 1, 1]]).float() # n classes 0 or 1 | |
print(preds, targets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imgs = np.arange(36).reshape(9, 2, 2) | |
print(imgs) | |
""" | |
array([[[ 0, 1], | |
[ 2, 3]], | |
[[ 4, 5], | |
[ 6, 7]], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def myloss(y, y_pred): | |
return ((y - y_pred) ** 2).mean() | |
np.random.seed(42) | |
x = np.arange(1, 21) | |
np.random.shuffle(x) | |
y = x * 2 - 1 | |
x = torch.FloatTensor(x).view(-1, 1) | |
y = torch.FloatTensor(y).view(-1, 1) |
Conv:
o = output
p = padding
k = kernel_size
s = stride
d = dilation
o = [i + 2*p - k - (k-1)*(d-1)]/s + 1
NewerOlder