Skip to content

Instantly share code, notes, and snippets.

View wac81's full-sized avatar

Arthur Wu wac81

View GitHub Profile
@wac81
wac81 / cross-entropy.ipynb
Created April 18, 2023 09:34 — forked from yang-zhang/cross-entropy.ipynb
Cross entropy implementation in pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wac81
wac81 / cross-entropy.ipynb
Created April 18, 2023 09:34 — forked from yang-zhang/cross-entropy.ipynb
Cross entropy implementation in pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wac81
wac81 / install-cuda-10-bionic.sh
Created February 15, 2023 06:40 — forked from bogdan-kulynych/install-cuda-10-bionic.sh
Install CUDA 10 on Ubuntu 18.04
# WARNING: These steps seem to not work anymore!
#!/bin/bash
# Purge existign CUDA first
sudo apt --purge remove "cublas*" "cuda*"
sudo apt --purge remove "nvidia*"
# Install CUDA Toolkit 10
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
@wac81
wac81 / cuda_11.1_installation_on_Ubuntu_18.04.md
Created February 15, 2023 02:35 — forked from hungntt/cuda_11.1_installation_on_Ubuntu_18.04.md
CUDA 11.1 Installation on Ubuntu 18.04

This gist contains instructions about cuda v11.1 and cudnn 8.0.4 installation in Ubuntu 18.04 for Tensorflow 2.4.1

  • If you have previous installation remove it first.
!/bin/bash
sudo apt-get purge *nvidia*
sudo apt remove --autoremove nvidia-*
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt remove --autoremove nvidia-cuda-toolkit
sudo apt-get autoremove && sudo apt-get autoclean
# ----------------------------
# Inference
# ----------------------------
def inference (model, val_dl):
correct_prediction = 0
total_prediction = 0
# Disable gradient updates
with torch.no_grad():
for data in val_dl:
@wac81
wac81 / How to build TensorFlow 2.0 on Ubuntu 18.04 (x86_64) with Bazelisk.md
Last active June 30, 2021 03:21 — forked from philwo/README.md
How to build TensorFlow 2.0 on Ubuntu 18.04 (x86_64) with Bazelisk

This is how I managed to build TensorFlow 2.0 on Ubuntu 18.04 (x86_64) with Bazelisk:

$ sudo apt update
$ sudo apt full-upgrade
$ sudo apt install curl

# Install Bazelisk.
$ sudo curl -Lo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.1.0/bazelisk-linux-amd64
$ sudo chmod +x /usr/local/bin/bazel
@wac81
wac81 / INSTALL.md
Created May 8, 2020 13:41 — forked from takeit/INSTALL.md
Write to NTFS on macOS Sierra (osxfuse + ntfs-3g)
  1. Install osxfuse:
brew cask install osxfuse
  1. Reboot your Mac.

  2. Install ntfs-3g:

@wac81
wac81 / sgdr.py
Created February 20, 2020 17:36 — forked from jeremyjordan/sgdr.py
Keras Callback for implementing Stochastic Gradient Descent with Restarts
from keras.callbacks import Callback
import keras.backend as K
import numpy as np
class SGDRScheduler(Callback):
'''Cosine annealing learning rate scheduler with periodic restarts.
# Usage
```python
schedule = SGDRScheduler(min_lr=1e-5,
@wac81
wac81 / keras2-highway-network.py
Created February 11, 2020 03:15 — forked from iskandr/keras2-highway-network.py
Since Keras 2.0 removed the Highway Network layer, here's my attempt at implementing something equivalent using the functional API
import keras.backend as K
from keras.layers import Dense, Activation, Multiply, Add, Lambda
import keras.initializers
def highway_layers(value, n_layers, activation="tanh", gate_bias=-3):
dim = K.int_shape(value)[-1]
gate_bias_initializer = keras.initializers.Constant(gate_bias)
for i in range(n_layers):
gate = Dense(units=dim, bias_initializer=gate_bias_initializer)(value)
gate = Activation("sigmoid")(gate)
@wac81
wac81 / kd.py
Created January 16, 2020 06:31 — forked from VictorSanh/kd.py
Knowledge Distilation
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.optim import Optimizer
KD_loss = nn.KLDivLoss(reduction='batchmean')
def kd_step(teacher: nn.Module,
student: nn.Module,
temperature: float,