Skip to content

Instantly share code, notes, and snippets.

View digital-thinking's full-sized avatar

Christian Freischlag digital-thinking

View GitHub Profile
@digital-thinking
digital-thinking / MappingLayer.py
Created August 27, 2020 09:46
Keras Layer to map raw indices to labels and only outputing the top n predictions (tensorflow 2)
class MappingLayer(tf.keras.layers.Layer):
"""
Converts probability outputs to TopN predictions applying a label mapping from indices to ids
"""
def __init__(self, mapping, topN):
super(MappingLayer, self).__init__()
initializer = tf.lookup.KeyValueTensorInitializer(
keys=tf.range(len(mapping)),
values=tf.constant(mapping, tf.int32),
@digital-thinking
digital-thinking / Base64DecoderLayer.py
Created August 27, 2020 09:45
Keras layer for Tensorflow Serve to accept base64 encoded jpeg images (tensorflow2)
class Base64DecoderLayer(tf.keras.layers.Layer):
"""
Convert a incoming base 64 string into an bitmap with rgb values between 0 and 1
target_size e.g. [width,height]
"""
def __init__(self, target_size):
self.target_size = target_size
super(Base64DecoderLayer, self).__init__()
@digital-thinking
digital-thinking / convert_tf_record.py
Last active May 21, 2021 07:25
Convert a list of jpg images into a fixed size TFRecord file
def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
for file in valid_files:
file_name = os.path.split(file)[1]
label = int(os.path.basename(os.path.split(file)[0]))
@digital-thinking
digital-thinking / .htaccess
Created October 2, 2015 08:26
Wordpress/Apache restrict access to subfolders (disable directory browser)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>