Skip to content

Instantly share code, notes, and snippets.

@schilli91
schilli91 / md_parser.py
Last active December 13, 2018 12:36
converts a markdown string to html and then to pdf
from markdown2 import Markdown
import pdfkit
GITHUB_CSS = "a.anchor,ol,ul{padding-left:30px}dl dt,table tr th{font-weight:700}body{font-family:Helvetica,arial,sans-serif;font-size:14px;line-height:1.6;background-color:#fff;padding:30px}body>:first-child{margin-top:0!important}h1 p,h2 p,h3 p,h4 p,h5 p,h6 p,ol :first-child,ul :first-child{margin-top:0}body>:last-child{margin-bottom:0!important}blockquote>:last-child,dl dd>:last-child,dl dt>:last-child,ol :last-child,table tr td :last-child,table tr th :last-child,ul :last-child{margin-bottom:0}a{color:#4183C4}a.absent{color:#c00}h1,h2{color:#000}blockquote,h6{color:#777}a.anchor{display:block;margin-left:-30px;cursor:pointer;position:absolute;top:0;left:0;bottom:0}dl,dl dt,dl dt:first-child,hr,table,table tr{padding:0}h1,h2,h3,h4,h5,h6{margin:20px 0 10px;padding:0;font-weight:700;-webkit-font-smoothing:antialiased;cursor:text;position:relative}h1:hover a.anchor,h2:hover a.anchor,h3:hover a.anchor,h4:hover a.anchor,h5:hover a.anchor,h6:hover a.anchor{background
@schilli91
schilli91 / tensorboard_smoothing.py
Created November 27, 2018 14:09
Applies smoothing according to Tensorboard to exported .csv files.
import csv
def tf_smooth_csv(in_file, out_file, smoothingWeight=0.6):
count = 0
last = -1
with open(in_file) as csvfile:
with open(out_file, 'w') as out:
reader = csv.DictReader(csvfile, delimiter=',')
writer = csv.DictWriter(out, fieldnames=["Step", "Value"])
@schilli91
schilli91 / tf_get_parameter_count_of_graph.py
Last active September 4, 2018 15:25
Calculates the parameter count required in the current graph.
# https://stackoverflow.com/questions/38160940/how-to-count-total-number-of-trainable-parameters-in-a-tensorflow-model
total_parameters = 0
for variable in tf.trainable_variables():
# shape is an array of tf.Dimension
shape = variable.get_shape()
# print("{}: {}".format(variable.name, shape))
variable_parameters = 1
for dim in shape:
variable_parameters *= dim.value
# print(variable_parameters)