Skip to content

Instantly share code, notes, and snippets.

View chenyaofo's full-sized avatar
😃
I may be slow to respond.

chenyaofo chenyaofo

😃
I may be slow to respond.
View GitHub Profile
# you can change the following hyper-parameter
penalty_factor = 0.5 # L2 regular term coefficients
learning_rate = 0.0005
max_epoch = 200
test_size = 0.25
# ------------------------------------------------------------------
# download the dataset
import requests
@chenyaofo
chenyaofo / mio_dataset.py
Created August 6, 2018 08:30
MIODataset
import copy
from torch.utils.data import Dataset
from torchlearning.mio import MIO, Split
class MioDataset(Dataset):
def __init__(self, root, sampler, transform=None, target_transform=None):
self.root = root
@chenyaofo
chenyaofo / install.sh
Last active May 6, 2019 08:50
my conda env
sh -c "$(wget https://gist.githubusercontent.com/chenyaofo/1ba93970fcfd0a05d46e84b30de2268c/raw/08572926d1ae81b45a2b6fa3df50a0d794f2c802/myenv.sh -O -)"
sh -c "$(wget https://gist.githubusercontent.com/chenyaofo/1ba93970fcfd0a05d46e84b30de2268c/raw/08572926d1ae81b45a2b6fa3df50a0d794f2c802/myenv_pip.sh -O -)"
@chenyaofo
chenyaofo / compare_pytorch_mxnet.py
Last active June 30, 2019 14:40
The API comparison between pytorch and mxnet
import numpy
import torch
import torch.nn
import mxnet
def test_forward_template(module_name, data, pt_module, mx_module, is_train=True):
print(f"Start to test forward process {module_name}, mode = {'train' if is_train else 'validating'}")
if not is_train:
pt_module.eval()
@chenyaofo
chenyaofo / auxnet.py
Created July 3, 2019 14:54
The core implementation of "The Shallow End: Empowering Shallower Deep-Convolutional Networks through Auxiliary Outputs"
import torch
import typing
import functools
import torch.nn as nn
def intermediate_output_hook(module, input, output, intermediate_output_store: list):
intermediate_output_store.append(output)
@chenyaofo
chenyaofo / dist.py
Created July 9, 2019 02:41
dist util
import os
import flame
import torch.distributed as dist
def init(backend="nccl", init_method="env://"):
if "RANK" in os.environ and "WORLD_SIZE" in os.environ:
if dist.is_available():
@chenyaofo
chenyaofo / dist.py
Created July 9, 2019 02:41
dist util
import os
import flame
import torch.distributed as dist
def init(backend="nccl", init_method="env://"):
if "RANK" in os.environ and "WORLD_SIZE" in os.environ:
if dist.is_available():
@chenyaofo
chenyaofo / Dockerfile
Last active June 24, 2020 02:01
pytorch1.3-py37
FROM nvidia/cuda:10.2-runtime-ubuntu18.04
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV PATH /opt/conda/bin:$PATH
RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
GIT_CLONE="git clone --depth 10" && \
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse' > /etc/apt/sources.list && \
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse' >> /etc/apt/sources.list && \
# syntax = docker/dockerfile:1.3
FROM nvidia/cuda:11.6.1-runtime-ubuntu20.04
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 \
PATH=/opt/conda/bin:$PATH \
TZ=Asia/Shanghai \
PYTHON_VERSION=3.9
RUN --mount=type=cache,target=/var/cache/apt,id=apt_cache0,sharing=locked --mount=type=cache,target=/var/lib/apt,id=apt_cache1,sharing=locked \
APT_INSTALL="apt-get install -y --no-install-recommends --no-install-suggests" && \
# syntax = docker/dockerfile:1.3
FROM python:3.9-slim as builder
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential