Skip to content

Instantly share code, notes, and snippets.

View zmonoid's full-sized avatar
🎯
Focusing

zmonoid

🎯
Focusing
View GitHub Profile
def insert_sort(A, reverse=False):
for j in range(1, len(A)):
key = A[j]
i = j - 1
# Insert A[j] to sorted sequence of A[:j]
if reverse:
@zmonoid
zmonoid / prefetcher.py
Created December 28, 2018 11:58
Python Pretetcher
import threading
import queue
import time
class BackgroundGenerator(threading.Thread):
def __init__(self, generator,max_prefetch = 100):
threading.Thread.__init__(self)
self.queue = queue.Queue(max_prefetch)
@zmonoid
zmonoid / async_example.py
Created December 28, 2018 10:43
Asyncio Example
import asyncio
# Borrowed from http://curio.readthedocs.org/en/latest/tutorial.html.
async def countdown(number, n):
while n > 0:
print('T-minus', n, '({})'.format(number))
yield from asyncio.sleep(1)
n -= 1
loop = asyncio.get_event_loop()
@zmonoid
zmonoid / PLTMeterLogger.py
Created December 14, 2018 11:29
MatPlotLib Meter Logger
import numpy as np
import matplotlib.pyplot as plt
import torch
class ValueMeter:
def __init__(self):
self.reset()
def add(self, value):
self.values.append(value)
@zmonoid
zmonoid / cma_es_walker.py
Last active July 19, 2018 12:22
CMA-ES for walker with Using OpenMPI
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 bzhou <bzhou@server2>
#
# Distributed under terms of the MIT license.
"""
mpirun -c 64 --hostfile hosts.txt python ~/cloud/es_walker.py
@zmonoid
zmonoid / primes.py
Last active June 4, 2018 17:28
This is to solve one of euler project's problem
def find_prime_till(d):
assert d > 10
x = [True] * (d+1)
x[0] = False
x[1] = False
last_prime = 2
while True:
k = last_prime*2
while k < d+1:
x[k] = False
@zmonoid
zmonoid / warmup.py
Created February 25, 2018 07:44
OpenAI Request 2.0 Warmups
import numpy as np
import torch
import torch.nn as nn
import torch.utils.data as data
from torch.autograd import Variable
class BinaryData(data.Dataset):
def __init__(self):
@zmonoid
zmonoid / create_tfrecords.py
Created November 24, 2017 12:18
Create TFRecords
"""
Create the tfrecord files for a dataset.
A lot of this code comes from the tensorflow inception example, so here is their license:
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@zmonoid
zmonoid / eval_imagenet.py
Last active November 21, 2017 14:34
Evaludate imagenet tfrecord
import tensorflow as tf
import numpy as np
from nets.nets_factory import get_network_fn
from preprocessing.preprocessing_factory import get_preprocessing
import glob
class Config:
batch_size = 32
num_epoch = 1
name = 'resnet_v2_50'
@zmonoid
zmonoid / classify_single_image.py
Last active November 21, 2017 11:41
Read Single Tensorflow Image
"""
put the file under slim folder like: models/research/slim/classify_single_image.py
save checkpoint files under slim/checkpoints/*.ckpt
save class id to label text file like slim/imagenet1000_clsid_to_human.txt, download from https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a
put test images *.jpg under slim
run it!
"""