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 a simple TF Graph | |
# By Omid Alemi - Jan 2017 | |
# Works with TF <r1.0 | |
import tensorflow as tf | |
I = tf.placeholder(tf.float32, shape=[None,3], name='I') # input | |
W = tf.Variable(tf.zeros_initializer(shape=[3,2]), dtype=tf.float32, name='W') # weights | |
b = tf.Variable(tf.zeros_initializer(shape=[2]), dtype=tf.float32, name='b') # biases | |
O = tf.nn.relu(tf.matmul(I, W) + b, name='O') # activation / output |
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 torch | |
from torchvision import models | |
def parse(net, inputs = torch.randn(1, 3, 224, 224)): | |
with torch.onnx.set_training(net, False): | |
trace = torch.onnx.utils._trace(net, inputs) | |
graph = trace.graph() | |
for n in graph.nodes(): | |
print(n.scopeName(), n.kind()) |
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 | |
from caffe2.python import ( | |
brew, | |
model_helper, | |
optimizer, | |
workspace, | |
utils, | |
) | |
from caffe2.proto import caffe2_pb2 |
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
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <sstream> | |
#include <google/protobuf/text_format.h> | |
// for read_from_pbtxt_nocopy | |
#include <fcntl.h> |
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 strip_consts(graph_def, max_const_size=32): | |
"""Strip large constant values from graph_def.""" | |
strip_def = tf.GraphDef() | |
for n0 in graph_def.node: | |
n = strip_def.node.add() | |
n.MergeFrom(n0) | |
if n.op == 'Const': | |
tensor = n.attr['value'].tensor | |
size = len(tensor.tensor_content) | |
if size > max_const_size: |
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 collections | |
import numpy as np | |
import itertools | |
SSDBoxSizes = collections.namedtuple('SSDBoxSizes', ['min', 'max']) | |
Spec = collections.namedtuple('Spec', ['feature_map_size', 'shrinkage', 'box_sizes', 'aspect_ratios']) | |
# the SSD orignal specs | |
specs = [ |
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
r"""Convert an ImageNet like dataset into tfRecord files, provide a method get_dataset to read the created files. | |
It has similar functions as ImageFolder in Pytorch. | |
Modified from | |
https://raw.githubusercontent.com/tensorflow/models/master/research/slim/datasets/download_and_convert_flowers.py | |
https://github.com/tensorflow/models/blob/master/research/slim/datasets/flowers.py | |
""" | |
from __future__ import absolute_import |
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 | |
def compute_average_precision(test_results, num_true_cases): | |
""" | |
It computes average precision based on the definition of Pascal Competition. It computes the under curve area | |
of precision and recall. Recall follows the normal definition. Precision is a variant. | |
pascal_precision[i] = typical_precision[i:].max() | |
Usage: | |
test_results = np.array([True, False, True, False, True, False, False, False, False, True]) |
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 datetime import datetime | |
import json | |
class Timer: | |
def __init__(self, outputFile): | |
self.fout = open(outputFile, 'w') | |
self.cache = [] | |
self.records = {} | |
def start(self, event="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
#include <stdio.h> | |
#define N (32) | |
__global__ void increment(int* time) { | |
__shared__ float s[1024]; | |
for (int i = 0; i < 1024; i++) { | |
s[i] = 1.0f; | |
} |
NewerOlder