This file contains hidden or 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 json | |
import scrapy | |
from scraper4.items import Scraper4Item | |
class MediumSpider(scrapy.Spider): | |
name = 'medium' | |
allowed_domains = ['medium.com'] | |
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Author: Dibyaranjan Sathua | |
Created on: 2019-02-28 12:26:54 | |
""" | |
import tensorflow as tf |
This file contains hidden or 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 cv2 | |
import numpy as np | |
def test_dnn_module(): | |
""" Function to test OpenCV DNN module. """ | |
model = 'removed_dropout_graph.pb' | |
net = cv2.dnn.readNet(model) | |
img = cv2.imread('F1_R0_A.png') | |
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
imgGray = imgGray.astype(np.uint8) |
This file contains hidden or 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.core.framework import graph_pb2 | |
import copy | |
def remove_dropout(input_graph, output_graph): | |
""" Remove the dropout block from the model. """ | |
graph_def = load_graph(input_graph) | |
new_graph_def = graph_pb2.GraphDef() | |
for node in graph_def.node: |
This file contains hidden or 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.core.framework import graph_pb2 | |
import copy | |
def optimize_batch_normalization(input_graph, output_graph): | |
""" Optimize the batch normalization block. """ | |
graph_def = load_graph(input_graph) # Defined above | |
new_graph_def = graph_pb2.GraphDef() | |
unused_attrs = ['is_training'] # Attributes of FusedBatchNorm. Not needed during inference. |
This file contains hidden or 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.core.framework import graph_pb2 | |
import copy | |
def load_graph(filename): | |
""" Use to read the tensorflow protobuf graph file. """ | |
graph_def = tf.GraphDef() | |
with tf.gfile.FastGFile(filename, 'rb') as f: | |
graph_def.ParseFromString(f.read()) | |
return graph_def |
This file contains hidden or 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.tools.graph_transforms import TransformGraph | |
def transform_graph(input_graph, output_graph): | |
""" Use to run different transform function on the input graph and generate a output graph. """ | |
with tf.gfile.GFile(input_graph, 'rb') as fid: | |
od_graph_def = tf.GraphDef() | |
serialized_graph = fid.read() | |
od_graph_def.ParseFromString(serialized_graph) | |
od_graph_def = TransformGraph(od_graph_def, ['input_placeholder/input_image'], ['predicated_output'], |