Skip to content

Instantly share code, notes, and snippets.

View wenfahu's full-sized avatar
🎯
Focusing

Bran Stewart wenfahu

🎯
Focusing
  • Intel
  • Beijing
View GitHub Profile
layer {
name: "train-data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mirror: true
@wenfahu
wenfahu / triplet_loss.py
Last active August 25, 2018 05:53
hard margin smooth hinge triplet loss
def triplet_loss(anchor, positive, negative, alpha):
"""Calculate the triplet loss according to the FaceNet paper
Args:
anchor: the embeddings for the anchor images.
positive: the embeddings for the positive images.
negative: the embeddings for the negative images.
Returns:
the triplet loss according to the FaceNet paper as a float tensor.
@wenfahu
wenfahu / triplet_loss.py
Last active August 6, 2018 10:30
soft margin smooth hinge
def triplet_loss_soft(anchor, positive, negative, m=1):
"""Calculate the triplet loss according to the FaceNet paper
Args:
anchor: the embeddings for the anchor images.
positive: the embeddings for the positive images.
negative: the embeddings for the negative images.
Returns:
the triplet loss according to the FaceNet paper as a float tensor.
from collections import defaultdict
import numpy as np
import pdb
from IPython import embed
sky = defaultdict(list)
def find_tuple(pts, tgts):
idx = []
@wenfahu
wenfahu / readme.rst
Last active September 4, 2017 02:09

Overall process

This toolset provides channel level pruning of inception-renet v2 model( the details of inception resnet v2 model, please refer to .. _Inception-ResnetV2: https://arxiv.org/abs/1602.07261

  1. python inf.py [meta] [ckpt] [output_mask] --threshold [threshold] : get the indices (mask) for the convolutional channel weights under the threshold.
  2. python freeze_graph.py [model_dir] [output_file]: freeze the model weights
  3. simplify the tensorflow graph using .. GTT: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/graph_transforms/README.md#optimizing-for-deployment
  4. python conv_travser.py [graph_path] [mask_path] [output_graph] [output_mask]: prune the model based on the dependency of inception resnet v2, the output_graph is the pruned model and the output_mask is used for further training.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import numpy as np
import pickle
from tensorflow.core.framework import attr_value_pb2
from tensorflow.core.framework import graph_pb2
from tensorflow.core.framework import node_def_pb2
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import numpy as np
import pickle
from tensorflow.core.framework import attr_value_pb2
from tensorflow.core.framework import graph_pb2
from tensorflow.core.framework import node_def_pb2
This file has been truncated, but you can view the full file.
This file has been truncated, but you can view the full file.
This file has been truncated, but you can view the full file.