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 tensorflow as tf | |
import torch | |
import numpy as np | |
def gather_nd_torch(params, indices, batch_dim=1): | |
""" A PyTorch porting of tensorflow.gather_nd | |
This implementation can handle leading batch dimensions in params, see below for detailed explanation. | |
The majority of this implementation is from Michael Jungo @ https://stackoverflow.com/a/61810047/6670143 | |
I just ported it compatible to leading batch dimension. |
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 torch | |
import tensorflow as tf | |
import time | |
import numpy as np | |
def gather_nd_torch(params, indices, batch_dim=1): | |
""" A PyTorch porting of tensorflow.gather_nd | |
This implementation can handle leading batch dimensions in params, see below for detailed explanation. |
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
# Authors: Mathieu Blondel, Vlad Niculae | |
# License: BSD 3 clause | |
import numpy as np | |
def _gen_pairs(gen, max_iter, max_inner, random_state, verbose): | |
rng = np.random.RandomState(random_state) | |
# if tuple, interpret as randn |
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 FocalLoss(nn.Module): | |
def __init__(self, gamma=2): | |
super().__init__() | |
self.gamma = gamma | |
def forward(self, logit, target): | |
target = target.float() | |
max_val = (-logit).clamp(min=0) | |
loss = logit - logit * target + max_val + \ | |
((-max_val).exp() + (-logit - max_val).exp()).log() |
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 get_senet50(config): | |
model = se_resnext50_32x4d(pretrained='imagenet') | |
# print(model.last_linear) | |
# print(model.dropout) | |
model.layer0.conv1 = nn.Conv2d(config.channels, 64, 3, stride=2, padding=1, bias=False) | |
model.avg_pool = nn.AdaptiveAvgPool2d(1) | |
model.dropout = None | |
model.last_linear = nn.Sequential( | |
nn.BatchNorm1d(2048), | |
nn.Dropout(0.5), |
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 multi_weighted_logloss(y_ohe, y_p): | |
""" | |
@author olivier https://www.kaggle.com/ogrellier | |
multi logloss for PLAsTiCC challenge | |
""" | |
classes = [6, 15, 16, 42, 52, 53, 62, 64, 65, 67, 88, 90, 92, 95] | |
class_weight = {6: 1, 15: 2, 16: 1, 42: 1, 52: 1, 53: 1, 62: 1, 64: 2, 65: 1, 67: 1, 88: 1, 90: 1, 92: 1, 95: 1} | |
# Normalize rows and limit y_preds to 1e-15, 1-1e-15 | |
y_p = np.clip(a=y_p, a_min=1e-15, a_max=1-1e-15) | |
# Transform to log |
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 Node: | |
def __init__(self, val): | |
self.val = val | |
self.next = None | |
class MyLinkedList: | |
def __init__(self): | |
""" | |
Initialize your data structure here. |
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 tensorflow as tf | |
import numpy as np | |
import os | |
import zconfig | |
import utils | |
class DenoisingAutoencoder(object): | |
""" Implementation of Denoising Autoencoders using TensorFlow. |
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
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets | |
import numpy as np | |
import timeit | |
import tensorflow as tf | |
from pprint import pformat | |
mnist = read_data_sets("data", one_hot=False) | |
NUM_CLASS = 10 | |
STEP = 200 |
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
% Author: Ji Yang | |
%% Description | |
% A simple implementation of histogram equalization. | |
% | |
%% Note | |
% Histogram equalization is a technique for adjusting image intensities | |
% to enhance contrast. | |
% |
NewerOlder