Skip to content

Instantly share code, notes, and snippets.

View kevashcraft's full-sized avatar

Kevin Ashcraft kevashcraft

View GitHub Profile
clearInterval(aa)
function mv() {
var found_one = false
var primary = 0
let el = document.querySelectorAll('.mlbtv-media-player')[primary]
let has_ads = !!el.querySelector('.interruption-link')
if (!has_ads) {
el.querySelector('video').muted = false
@kevashcraft
kevashcraft / favicon.sh
Created July 11, 2019 22:55
Create ico from png
convert logo.png -define icon:auto-resize=64,48,32,16 logo.ico
@kevashcraft
kevashcraft / TFRecord-Writer.py
Last active February 4, 2020 16:32
Writing a TFRecord File
with tf.io.TFRecordWriter('examples.tfrecord') as training_file:
for features, label in batch:
features = {
'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),
'features': tf.train.Feature(float_list=tf.train.FloatList(value=features)) # expects list, so if numpy use .tolist() and ensure it's 1-D
}
example_proto = tf.train.Example(features=tf.train.Features(feature=features))
training_file.write(example_proto.SerializeToString())
@kevashcraft
kevashcraft / TFrecord-Reader.py
Created February 4, 2020 16:36
Reading a TFRecord File
label_size = 1 # the length of the previously written label
feature_size = 256 # the length of the previously written feature lists
def map_fn(serialized_example):
feature = {
'label': tf.io.FixedLenFeature([label_)size], tf.int64),
'features': tf.io.FixedLenFeature([feature_size], tf.float32)
}
example = tf.io.parse_single_example(serialized_example, feature)
features = example['features']
label = tf.cast(example['label'], tf.int32)
@kevashcraft
kevashcraft / TFRecord-Writer.py
Last active February 7, 2020 18:49
Writing a TFRecord File
# Write a ambient, target, and label data to a TFRecords file
with tf.io.TFRecordWriter('examples.tfrecord') as training_file:
for ambient, target, label in batch: # batch is a list of (ambient, target, label) tuples
features = {
'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),
'ambient': tf.train.Feature(float_list=tf.train.FloatList(value=ambient.tolist())), # ambient is a 1-D np array
'target': tf.train.Feature(float_list=tf.train.FloatList(value=target.tolist())) # target is a 1-D np array
}
example_proto = tf.train.Example(features=tf.train.Features(feature=features))
training_file.write(example_proto.SerializeToString())
@kevashcraft
kevashcraft / Read-TFRecord.py
Created February 7, 2020 18:37
Read TFRecord File into TF Dataset
# Read a TFRecord file into a TF Dataset
def map_fn(serialized_example):
feature = {
'label': tf.io.FixedLenFeature([1], tf.int64),
'ambient': tf.io.FixedLenFeature([16000], tf.float32),
'target': tf.io.FixedLenFeature([4000], tf.float32)
}
example = tf.io.parse_single_example(serialized_example, feature)
ambient = tf.expand_dims(example['ambient'], 1)
target = tf.expand_dims(example['target'], 1)
@kevashcraft
kevashcraft / TFDataset-Take.py
Created February 7, 2020 18:42
Iterating Through TF Dataset
# if dataset is not batched
# this will take 1 example
with (ambient, target), label in dataset.take(1):
print("ambient shape", ambient.shape)
print("target shape", target.shape)
print("label shape", label.shape)
ambient_array = ambient.numpy()
target_array = target.numpy()
label_array = label.numpy()