Skip to content

Instantly share code, notes, and snippets.

View TheodoreGalanos's full-sized avatar

Theodore Galanos TheodoreGalanos

View GitHub Profile
# fixed version of http://altons.github.io/python/2012/12/01/converting-northing-and-easting-to-latitude-and-longitude/
# - filenames
# - data type (pyproj transform doesn't like pandas series)
import os
import pandas as pd
import pyproj
import re
listfiles = os.listdir("codepo/Data/CSV")
pieces = []
@kevinzakka
kevinzakka / data_loader.py
Last active April 19, 2024 23:42
Train, Validation and Test Split for torchvision Datasets
"""
Create train, valid, test iterators for CIFAR-10 [1].
Easily extended to MNIST, CIFAR-100 and Imagenet.
[1]: https://discuss.pytorch.org/t/feedback-on-pytorch-for-kaggle-competitions/2252/4
"""
import torch
import numpy as np
@marcolivierarsenault
marcolivierarsenault / lossless_triplet_loss.py
Created February 14, 2018 19:21
Lossless triplet loss
def lossless_triplet_loss(y_true, y_pred, N = 3, beta=N, epsilon=1e-8):
"""
Implementation of the triplet loss function
Arguments:
y_true -- true labels, required when you define a loss in Keras, you don't need it in this function.
y_pred -- python list containing three objects:
anchor -- the encodings for the anchor data
positive -- the encodings for the positive data (similar to anchor)
negative -- the encodings for the negative data (different from anchor)
@xuf12
xuf12 / load_text_files
Created April 7, 2018 16:06
loading text files to pandas
def get_texts(path):
rows_list = []
for idx, label in enumerate(CLASSES):
print(f'working on {path}/{label}')
for fname in (path/f'{label}').glob('*.*'):
dict1 = {}
text = fname.open('r').read()
dict1.update({
'text':text,
'label':idx
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rxwei
rxwei / ad-manifesto.md
Last active November 9, 2023 09:58
First-Class Automatic Differentiation in Swift: A Manifesto
@crowsonkb
crowsonkb / mdmm.py
Last active February 1, 2021 00:33
Modified Differential Multiplier Method
import torch
from torch import nn, optim
class Constraint(nn.Module):
def __init__(self, fn, maximum, damping=1e-2):
super().__init__()
self.fn = fn
self.register_buffer('maximum', torch.as_tensor(maximum))
self.register_buffer('damping', torch.as_tensor(damping))
@crowsonkb
crowsonkb / mnist_imle.py
Last active February 5, 2021 13:52
Trains IMLE on the MNIST dataset.
"""Trains IMLE on the MNIST dataset."""
import torch
from torch import optim, nn
from torch.nn import functional as F
from torch.utils import data
from torchvision import datasets, transforms, utils
from torchvision.transforms import functional as TF
from tqdm import tqdm
#!/usr/bin/env python3
import argparse
from collections import defaultdict
import csv
import math
import torch
from torch import nn, optim
from torch.nn import functional as F
# Modified StyleGAN2 Projector with CLIP, addl. losses, kmeans, etc.
# by Peter Baylies, 2021 -- @pbaylies on Twitter
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.