Skip to content

Instantly share code, notes, and snippets.

@leVirve
leVirve / CoordConv.py
Last active May 15, 2019 18:46
The real CoordConv in PyTorch. It can auto-infer the x-y dimensions in tensors. Use it without pain. 💜
class AddCoords(nn.Module):
def __init__(self, with_r=False):
super().__init__()
self.with_r = with_r
def forward(self, input_tensor):
"""
Args:
input_tensor: shape(batch, channel, x_dim, y_dim)
@leVirve
leVirve / docker-cleanup-resources.md
Created December 27, 2017 00:47 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@leVirve
leVirve / feature.py
Last active August 17, 2017 06:52
Override the behavior of `forward()` inside VGG from PyTorch torchvision.
import types
import torch
from torch.autograd import Variable
import torchvision.models as models
import torchvision.transforms as transforms
from torchvision.datasets.folder import pil_loader
@leVirve
leVirve / sget.py
Last active June 2, 2017 11:38
A script for proxy get.
#!/usr/bin/env python
import os
import sys
import time
import requests
remote_server = '{user}@{ip}'
port = 9487
proxies = {
'http': 'socks5://localhost:%d' % port,
@leVirve
leVirve / autoencoder.py
Last active April 4, 2017 16:57
Something about autoencoder-like network in Tensorflow, however the net structure is a crazy scribble. 😂 Just practice using file queue feature in TF.
import tensorflow as tf
def read_image(filename_queue):
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
img = tf.image.decode_jpeg(value)
img.set_shape((256, 512, 3))
export JAVA_HOME="$(ls -d C:/Program\ Files/Java/jdk* | sort | tail -n 1)"
export BAZEL_SH=c:/tools/msys64/usr/bin/bash.exe
export PATH=/c/ProgramData/Chocolatey/lib/bazel:"/c/Program Files/Git/cmd":$PATH
export BAZEL_VS="C:/Program Files (x86)/Microsoft Visual Studio 14.0"
export BAZEL_PYTHON="C:/Python27/python.exe"
@leVirve
leVirve / ddd_ftpuser.py
Last active November 23, 2021 09:34
A Python script to add/remove users for FileZilla Server.
import hashlib
import os
import subprocess
import xml.etree.ElementTree
import click
user_xml_fmt = '''
<User Name="ddd_{username}">
<Option Name="Pass">{md5_pwd}</Option>
@leVirve
leVirve / dcard-incremental-hack-version.py
Last active July 30, 2016 06:51
Hack my own `dcard-spider` and make it get the power of incremental crawling.
import time
import datetime
from dcard import Dcard
def hack_forums_get_meta_function(dcard):
target_date = datetime.datetime.utcnow() - datetime.timedelta(days=1)
@leVirve
leVirve / Note.md
Last active June 11, 2016 05:48
MIR Final Project
@leVirve
leVirve / kmeans.m
Created February 22, 2016 09:28
K-Means on RGB image
optns = statset('MaxIter', iters);
pixels = reshape(img(:), [], 3);
[idxs, centroids] = kmeans(pixels, k, 'options', optns);
img_map = centroids(idxs, :);
img_new = reshape(img_map(:), size(img));
imshow(img_new);