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
/** | |
* just for demo purpose, bugs maybe found | |
* g++ -shared -fPIC pyio.cc -o pyio.so -std=c++11 -I/usr/include/python2.7/ | |
* equilavent python code: | |
def write(filename, string): | |
global error | |
if not string: error = “empty string" | |
with open(filename, ‘w’) as f: | |
f.write(string) |
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
# coding: utf-8 | |
import math | |
from PIL import Image | |
from pdf2image import convert_from_path, convert_from_bytes | |
import sys,os | |
print(sys.argv) | |
inputpath = sys.argv[1] | |
outputpath = sys.argv[2] | |
filename = '.'.join(inputpath.split('/')[-1].split('.')[:-1]) |
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 | |
from tensorflow.python.client import timeline | |
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) | |
run_metadata = tf.RunMetadata() | |
predictions = use_sess.run(use_out, {'DecodeJpeg/contents:0': image_file.file.getvalue()}, options=run_options, run_metadata=run_metadata) | |
# Create the Timeline object, and write it to a json | |
tl = timeline.Timeline(run_metadata.step_stats) |
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
# Copyright 2017 The TensorFlow Authors. 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 | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, |
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
# -*- coding: utf-8 -*- | |
import os.path | |
# This is a placeholder for a Google-internal import. | |
import tensorflow as tf | |
import tensorflow.contrib.slim as slim | |
from nets import resnet_v2 | |
from preprocessing import vgg_preprocessing as vgg |
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 show_graph_details(graph, mark): | |
import tensorflow as tf | |
import pprint | |
if isinstance(graph, tf.GraphDef): | |
with tf.Session(graph=tf.Graph()) as sess: | |
tf.import_graph_def(graph) | |
graph = sess.graph | |
elif isinstance(graph, tf.MetaGraphDef): | |
with tf.Session(graph=tf.Graph()) as sess: | |
tf.import_graph_def(graph.graph_def) |
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
from tensorflow.python.client import device_lib | |
def get_available_gpus(): | |
local_device_protos = device_lib.list_local_devices() | |
return [x.name for x in local_device_protos if x.device_type == 'GPU'] |
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
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
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
#! /bin/sh - | |
# Build one or more packages in parallel on one or more build hosts. | |
# | |
# Usage: | |
# build-all [ --? ] | |
# [ --all "..." ] | |
# [ --cd "..." ] | |
# [ --check "..." ] | |
# [ --configure "..." ] | |
# [ --environment "..." ] |
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 os, sys | |
from flask import jsonify | |
import datetime | |
def convert_datatype(val): | |
if type(val) == dict: | |
converted = {} | |
for k in val: | |
if type(k) != unicode and type(k) != str: | |
raise TypeError('the key of dict must be strings.') |
NewerOlder