Skip to content

Instantly share code, notes, and snippets.

View tonyreina's full-sized avatar

Tony Reina tonyreina

View GitHub Profile
import cv2
import numpy as np
from scipy import ndimage
""" Erosion with OpenCV """
def Erosion_Opencv(img, kernel):
cv2.imshow("Input Image", img)
cv2.waitKey(0)
erosion = cv2.erode(img,kernel,iterations = 1)
from tensorflow.keras.utils import Sequence
import numpy as np
class DatasetGenerator(Sequence):
"""
TensorFlow Dataset from Python/NumPy Iterator
"""
def __init__(self, filenames, batch_size=8, crop_dim=[240,240], augment=False, seed=816):
@tonyreina
tonyreina / CLA
Last active February 10, 2021 23:21
Contribution License Agreement
This Contribution License Agreement ("Agreement") is agreed to by the party signing below ("You"), and conveys certain license rights to the Intel Corporation ("Intel") for Your contributions to Intel open source projects. This Agreement is effective as of the latest signature date below.
1. Definitions.
"Code" means the computer software code, whether in human-readable or machine-executable form, that is delivered by You to Intel under this Agreement.
"Project" means any of the projects owned or managed by Intel and offered under a license approved by the Open Source Initiative (www.opensource.org).
"Submit" is the act of uploading, submitting, transmitting, or distributing code or other content to any Project, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of discussing and improving that Project, but excluding communication that is
# !/usr/bin/env python
import tensorflow as tf
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2_as_graph
from tensorflow.lite.python.util import run_graph_optimizations, get_grappler_config
from pathlib import Path
import argparse
def frozen_keras_graph(model):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020 Intel Corporation
#
# 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
@tonyreina
tonyreina / convert.py
Created November 5, 2019 23:30
Summarize TensorFlow Graph for Inputs and Outputs
import argparse
import tensorflow as tf
import os
import sys
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
unlikely_output_types = ['Const', 'Assign', 'NoOp', 'Placeholder', 'Assert']
def dump_for_tensorboard(graph_def: tf.GraphDef, logdir: str):
# !/usr/bin/env python
"""
Copyright (c) 2018 Intel Corporation
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
@tonyreina
tonyreina / load_and_convert_protobuf.py
Last active September 4, 2019 19:40
Load TensorFlow protobuf
import tensorflow as tf
import argparse
parser = argparse.ArgumentParser(
description="Loads TensorFlow protobuf and converts it to saved model",
add_help=True, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--filename", required=True,
help="the name and path of the HDF5 dataset")
parser.add_argument("--input_layer_name", default="import/shuffled_queue:0",
@tonyreina
tonyreina / openvino_inference.py
Last active March 23, 2024 05:58
Generic script for doing inference on OpenVINO model
#!/usr/bin/env python
# python openvino_inference.py -l /opt/intel/openvino/inference_engine/lib/libcpu_extension.so
import sys
import os
from argparse import ArgumentParser
import numpy as np
import logging as log
from timeit import default_timer as timer
@tonyreina
tonyreina / Dynamically reshaping inputs to Keras model
Last active June 7, 2019 17:34
Calculate time it takes TensorFlow Keras to handle dynamic reshaping of model inputs
import numpy as np
import tensorflow as tf
num_channels = 3
def create_model():
"""
Generic fully-convolutional (FCN) model
Model inputs can be defined with size "None" so that they can
use different shapes each time. This works for FCN models