Skip to content

Instantly share code, notes, and snippets.

View JonnyTran's full-sized avatar
Brewing espresso

Jonny Tran JonnyTran

Brewing espresso
View GitHub Profile
@JonnyTran
JonnyTran / year-to-date workouts
Last active September 4, 2025 20:35
year-to-date workouts
🏂 63km ████████████▊░░░░░░░
🚶‍♂️ 21km ████▏░░░░░░░░░░░░░░░
‍🏃‍♂️ 12km ██▍░░░░░░░░░░░░░░░░░
🥾 2km ▏░░░░░░░░░░░░░░░░░░░
🧗 0km ░░░░░░░░░░░░░░░░░░░░
🕺🏻 0km ░░░░░░░░░░░░░░░░░░░░
🚴‍♂️ 0km ░░░░░░░░░░░░░░░░░░░░
🤸🏻 0km ░░░░░░░░░░░░░░░░░░░░
96km total
@JonnyTran
JonnyTran / pt_utils.py
Last active December 10, 2022 23:53
Useful pytorch functions
from typing import Dict, Tuple, Optional, Union, List
from torch_geometric.data import HeteroData
from torch_sparse import SparseTensor
from dgl.heterograph import DGLBlock, DGLHeteroGraph
from dgl._deprecate.graph import DGLGraph
from argparse import Namespace
from collections import OrderedDict
from collections.abc import MutableMapping
import torch
########### Data Loaders #############
def collate_fn(batch):
protein_seqs_all, physical, genetic, correlation, y_all, idx_all = [], [], [] ,[], [], []
for X, y, idx in batch:
protein_seqs_all.append(torch.tensor(X["Protein_seqs"]))
physical.append(torch.tensor(X["Protein-Protein-physical"]))
genetic.append(torch.tensor(X["Protein-Protein-genetic"]))
correlation.append(torch.tensor(X["Protein-Protein-correlation"]))
y_all.append(torch.tensor(y))
idx_all.append(torch.tensor(idx))
class OnlineTripletLoss(tf.keras.layers.Layer):
def __init__(self, directed_margin=0.2, undirected_margin=0.1, undirected_weight=1.0, **kwargs):
super(OnlineTripletLoss, self).__init__(**kwargs)
self.output_dim = ()
self.directed_margin = directed_margin
self.undirected_margin = undirected_margin
self.undirected_weight = undirected_weight
def build(self, input_shape):
assert isinstance(input_shape, list)