Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

ZHOU Bin zmonoid

Block or report user

Report or block zmonoid

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@zmonoid
zmonoid / prefetcher.py
Created Dec 28, 2018
Python Pretetcher
View prefetcher.py
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)
View async_example.py
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 Dec 14, 2018
MatPlotLib Meter Logger
View PLTMeterLogger.py
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 Jul 19, 2018
CMA-ES for walker with Using OpenMPI
View cma_es_walker.py
#! /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 / warmup.py
Created Feb 25, 2018
OpenAI Request 2.0 Warmups
View warmup.py
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):
View create_tfrecords.py
"""
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 Nov 21, 2017
Evaludate imagenet tfrecord
View eval_imagenet.py
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 Nov 21, 2017
Read Single Tensorflow Image
View classify_single_image.py
"""
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!
"""
@zmonoid
zmonoid / primes.py
Last active Jun 4, 2018
This is to solve one of euler project's problem
View primes.py
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
You can’t perform that action at this time.