Skip to content

Instantly share code, notes, and snippets.

@divamgupta
divamgupta / vat_example.ipynb
Created May 31, 2019 16:23
Simple keras implementation of Virtual Adversarial Training .
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import keras
from keras.models import Sequential
from keras.models import load_model
from keras.layers import Dense
from keras.optimizers import Adam
import numpy as np
import random
from collections import deque
@serycjon
serycjon / filter_events.py
Created September 20, 2018 09:33
Filter tensorflow event files
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import argparse
import tqdm
import tensorflow as tf
@ashokpant
ashokpant / cuda_9.0_cudnn_7.0.sh
Last active August 29, 2025 08:18
Install CUDA Toolkit v9.0 and cuDNN v7.0 on Ubuntu 16.04
#!/bin/bash
# install CUDA Toolkit v9.0
# instructions from https://developer.nvidia.com/cuda-downloads (linux -> x86_64 -> Ubuntu -> 16.04 -> deb)
CUDA_REPO_PKG="cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb"
wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/${CUDA_REPO_PKG}
sudo dpkg -i ${CUDA_REPO_PKG}
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda-9-0
@erogol
erogol / dataset_mongo.py
Last active September 19, 2024 12:21
PyTorch MongoDB dataset interface
import io
import os
import numpy as np
from PIL import Image
from pymongo import MongoClient
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms
def pil_loader(f):
@ikhlestov
ikhlestov / custom_data_loader.py
Created September 13, 2017 19:41
pytorch: custom data loader
import torch
import torchvision as tv
class ImagesDataset(torch.utils.data.Dataset):
def __init__(self, df, transform=None,
loader=tv.datasets.folder.default_loader):
self.df = df
self.transform = transform
self.loader = loader
@bartolsthoorn
bartolsthoorn / multilabel_example.py
Created April 29, 2017 12:13
Simple multi-laber classification example with Pytorch and MultiLabelSoftMarginLoss (https://en.wikipedia.org/wiki/Multi-label_classification)
import torch
import torch.nn as nn
import numpy as np
import torch.optim as optim
from torch.autograd import Variable
# (1, 0) => target labels 0+2
# (0, 1) => target labels 1
# (1, 1) => target labels 3
train = []
@karpathy
karpathy / min-char-rnn.py
Last active March 21, 2026 03:14
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@somada141
somada141 / python_dicom_load_pydicom.md
Created March 2, 2015 10:30
Load DICOM data into a NumPy array with PyDICOM #python #dicom #medical #imagedata #pydicom #fileIO
@samueljackson92
samueljackson92 / otsu.py
Last active December 24, 2020 04:15
Otsu's method of thresholding. Partially based on the implementation shown at: http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html
#!/usr/local/bin/python
#######################################################
# Otsu's Method
# Author: Samuel Jackson (samueljackson@outlook.com)
# Date: 21/07/2013
# Description: Performs Otsu's method of thresholding
# using the between class variance.
#######################################################