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
| ######## WebCam Object Detection Using Tensorflow Classifier ######### | |
| # Description: | |
| # This program uses a TensorFlow classifier to perform object detection. | |
| # It loads the classifier uses it to perform object detection on a WebCam feed. | |
| # It draws boxes and scores around the objects of interest in each frame from | |
| # the WebCam. It also can be used with picamera by adding "--picamera" | |
| # when executing this script from the terminal. | |
| # Import packages | |
| import os |
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 numpy as np | |
| import tensorflow as tf | |
| from tensorflow_model_optimization.sparsity import keras as sparsity | |
| # Backend agnostic way to save/restore models | |
| # _, keras_file = tempfile.mkstemp('.h5') | |
| # print('Saving model to: ', keras_file) | |
| # tf.keras.models.save_model(model, keras_file, include_optimizer=False) | |
| # Load the serialized model |
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 gizeh as gz | |
| from matplotlib import pyplot as plt | |
| from PIL import Image | |
| %matplotlib inline | |
| from drawing_dataset import DrawingDataset | |
| dataset = DrawingDataset('./data/quick_draw_pickles/', './data/label_mapping.jsonl') | |
| dataset.setup() | |
| strokes = dataset.get_drawing('cat', 0) |
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
| from keras import backend as K | |
| import tensorflow as tf | |
| def freeze_session(session, keep_var_names=None, output_names=None, clear_devices=True): | |
| """ | |
| Freezes the state of a session into a pruned computation graph. | |
| Creates a new computation graph where variable nodes are replaced by | |
| constants taking their current value in the session. The new graph will be | |
| pruned so subgraphs that are not necessary to compute the requested |
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 numpy as np | |
| from tensorflow import keras | |
| from tensorflow.keras.models import Sequential | |
| from tensorflow.keras.layers import Dense | |
| from tensorflow.keras import backend as K | |
| def cosine_decay_with_warmup(global_step, | |
| learning_rate_base, | |
| total_steps, |
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
| def yolo_non_max_suppression(scores, boxes, classes, max_boxes = 10, iou_threshold = 0.5): | |
| """ | |
| Applies Non-max suppression (NMS) to set of boxes | |
| Arguments: | |
| scores -- tensor of shape (None,), output of yolo_filter_boxes() | |
| boxes -- tensor of shape (None, 4), output of yolo_filter_boxes() that have been scaled to the image size (see later) | |
| classes -- tensor of shape (None,), output of yolo_filter_boxes() | |
| max_boxes -- integer, maximum number of predicted boxes you'd like | |
| iou_threshold -- real value, "intersection over union" threshold used for NMS filtering |
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.python.framework import graph_io | |
| from tensorflow.keras.models import load_model | |
| # Clear any previous session. | |
| tf.keras.backend.clear_session() | |
| save_pb_dir = './model' | |
| model_fname = './model/model.h5' |
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
| def get_mfccs(audio_file=None ,signals=None, sample_rate = 44100, num_mfccs = 13, frame_length=1024, frame_step=512, fft_length=1024, fmax=8000, fmin=80): | |
| """Compute the MFCCs for audio file | |
| Keyword Arguments: | |
| audio_file {str} -- audio wav file path (default: {None}) | |
| signals {tensor} -- input signals as tensor or np.array in float32 type (default: {None}) | |
| sample_rate {int} -- sampling rate (default: {44100}) | |
| num_mfccs {int} -- number of mfccs to keep (default: {13}) | |
| frame_length {int} -- frame length to compute STFT (default: {1024}) | |
| frame_step {int} -- frame step to compute STFT (default: {512}) |
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 | |
| def get_frozen_graph(graph_file): | |
| """Read Frozen Graph file from disk.""" | |
| with tf.gfile.FastGFile(graph_file, "rb") as f: | |
| graph_def = tf.GraphDef() | |
| graph_def.ParseFromString(f.read()) | |
| return graph_def | |
| # The TensorRT inference graph file downloaded from Colab or your local machine. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder