This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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! | |
""" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |