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.
[{"query": "china economy", "res": [{"contributors": null, "truncated": false, "text": "RT @KatiePilbeamIG: China's economy in 2017. https://t.co/v78JbOzr6x", "is_quote_status": true, "in_reply_to_status_id": null, "id": 814461641647685632, "favorite_count": 0, "entities": {"symbols": [], "user_mentions": [{"id": 702832773988544512, "indices": [3, 18], "id_str": "702832773988544512", "screen_name": "KatiePilbeamIG", "name": "Katie"}], "hashtags": [], "urls": [{"url": "https://t.co/v78JbOzr6x", "indices": [45, 68], "expanded_url": "https://twitter.com/IGTV/status/814424627523022849", "display_url": "twitter.com/IGTV/status/81\u2026"}]}, "quoted_status_id": 814424627523022849, "retweeted": false, "coordinates": null, "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>", "in_reply_to_screen_name": null, "in_reply_to_user_id": null, "retweet_count": 1, "id_str": "814461641647685632", "favorited": false, "retweeted_status": {"contributors": null, "truncated": false,
This file has been truncated, but you can view the full file.
[{"query": "now2016 nowladygaga", "res": [{"contributors": null, "truncated": false, "text": "RT @suporteladygaga: MONSTERS VOTANDO\n#NOW2016 #NOWLadyGaga https://t.co/SpCM7zFBpB", "is_quote_status": false, "in_reply_to_status_id": null, "id": 814453454659796992, "favorite_count": 0, "entities": {"symbols": [], "user_mentions": [{"id": 882160322, "indices": [3, 19], "id_str": "882160322", "screen_name": "suporteladygaga", "name": "Suporte Lady Gaga"}], "hashtags": [{"indices": [38, 46], "text": "NOW2016"}, {"indices": [47, 59], "text": "NOWLadyGaga"}], "urls": [], "media": [{"source_user_id": 882160322, "source_status_id_str": "814296174777798656", "expanded_url": "https://twitter.com/suporteladygaga/status/814296174777798656/photo/1", "display_url": "pic.twitter.com/SpCM7zFBpB", "url": "https://t.co/SpCM7zFBpB", "media_url_https": "https://pbs.twimg.com/media/C0z2CMqXAAA0Vom.jpg", "source_user_id_str": "882160322", "source_status_id": 814296174777798656, "id_str": "814296150266281984", "sizes": {"large": {"h
This file has been truncated, but you can view the full file.
[{"query": "videomtv2016", "res": [{"contributors": null, "truncated": false, "text": "RT @Projeto5HVotes: Dinah \n#Now2016 #NOWFifthHarmony #VideoMTV2016 Fifth Harmony", "is_quote_status": false, "in_reply_to_status_id": null, "id": 813347580759470080, "favorite_count": 0, "entities": {"symbols": [], "user_mentions": [{"id": 4249453102, "indices": [3, 18], "id_str": "4249453102", "screen_name": "Projeto5HVotes", "name": "Projeto 5H Votes"}], "hashtags": [{"indices": [27, 35], "text": "Now2016"}, {"indices": [36, 52], "text": "NOWFifthHarmony"}, {"indices": [53, 66], "text": "VideoMTV2016"}], "urls": []}, "retweeted": false, "coordinates": null, "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>", "in_reply_to_screen_name": null, "in_reply_to_user_id": null, "retweet_count": 54, "id_str": "813347580759470080", "favorited": false, "retweeted_status": {"contributors": null, "truncated": false, "text": "Dinah \n#Now2016 #NOWFifthHarmony #VideoMTV2016 Fifth Harmony