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
if __name__ == '__main__': | |
import cProfile | |
cProfile.run('unittest.main()', 'b1') | |
import pstats | |
p = pstats.Stats('b1') | |
p.sort_stats('cumulative').print_stats(20) | |
print() |
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
''' | |
Utilities to save/load torch models. | |
Same as built-in torch.save/torch.load, but support cloud URLs | |
''' | |
import tensorflow.gfile as gio | |
import io | |
import torch | |
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
''' | |
Super dirty trick to replace io of tensorboardX.SummaryWriter with cloud-capable one (from tensorflow.gfile) | |
''' | |
import tensorboardX | |
import tensorflow.gfile as gio | |
from unittest import mock | |
import logging | |
import time |
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 make_overlay(imagename, box, outname): | |
'''creates a PNG image of base with overlayed colored boxes. Useful for human review''' | |
if 'size' not in box: | |
return | |
img = Image.open(imagename).convert('RGB') | |
draw = ImageDraw.Draw(img, 'RGBA') | |
for key,color in [ | |
('title', (255, 0, 0, 128)), |
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 random | |
class Rule: | |
def __init__(self, name): | |
self.name = name | |
GRAMMAR = { | |
'op': ['+', '-', '/', '%', '*'], | |
'var': ['x', 'y', 'z', '1', '2', '3'], |
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 unittest | |
import queue | |
class BlockPipe: | |
'''a file-like object that implements Pipe protocol | |
using blocking queue | |
''' | |
def __init__(self, maxsize=0): |
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
pipeline { | |
// use only nodes marked as 'tensorflow' | |
agent { node { label 'tensorflow' } } | |
// build parameters - these are prompted interactively | |
parameters { | |
string(defaultValue: '', description: 'Problem Name', name: 'problem') | |
} | |
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 socket | |
import json | |
from urllib import request | |
import time | |
from izutil.progress import NULL_PROGRESS_METER | |
class ILabsEngine: | |
URL_UPLOAD = 'https://api.innodatalabs.com/v1/documents/input/' | |
URL_PREDICT = 'https://api.innodatalabs.com/v1/reference/{domain}/{name}' |
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
class DomainMap: | |
_map = None | |
@classmethod | |
def _get(cls): | |
raise NotImplementedError('heavy work done here (someday)') | |
@classmethod | |
def get(cls): |
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
class DomainMap: | |
_domain_map = None | |
@classmethod | |
def _get(cls): | |
# do heavy lifting here | |
# result = ... | |
return result | |
@classmethod |