Skip to content

Instantly share code, notes, and snippets.

View phisad's full-sized avatar

Philipp phisad

  • Berlin
View GitHub Profile
@phisad
phisad / tf-starter.py
Last active January 18, 2019 11:07
Tensorflow gpu starter (tensorflow-gpu 1.12 with CUDA 10.0)
import os
import tensorflow as tf;
# Just disables the warning, doesn't enable AVX/FMA
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
def main():
tf.enable_eager_execution();
result = tf.reduce_sum(tf.random_normal([1000,1000]))
print(result)
@phisad
phisad / index.html
Created January 30, 2019 09:01
JSF welcome file for root context with redirect to landing page (somehow only HTML worked, but not XHTML)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="0; URL=landing_page.xhtml" ></meta>
</head>
<body>
</body>
</html>
@phisad
phisad / Tab.java
Created February 28, 2019 18:29
Primefaces 6.2 tabs with c:forEach
package de.phisad.mybudget.views.budgetplan;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class Tab {
private String name;
public Tab(String name) {
@phisad
phisad / connected_graph.py
Created March 6, 2019 22:05
Keras disconnected graphs example when using multiple models
def test_connected_models(self):
input1 = Input(shape=(100,))
dense1 = Dense(1)(input1)
model1 = Model(input1, dense1)
input2 = Input(shape=(200,))
dense2 = Dense(2)(input2)
model2 = Model(input2, dense2)
# This will work, because there are no intermediate Inputs.
@phisad
phisad / equals-code-template.xml
Last active March 13, 2019 08:45
Eclipse code template for equals hash toString with apache commons lang3
${:import(org.apache.commons.lang3.builder.EqualsBuilder,
org.apache.commons.lang3.builder.HashCodeBuilder,
org.apache.commons.lang3.builder.ToStringBuilder,
org.apache.commons.lang3.builder.ToStringStyle)}
@Override
public boolean equals(Object aObj) {
if(!(aObj instanceof ${enclosing_type})) {
return false;
}
@phisad
phisad / text_sequence_preprocessing.py
Created March 15, 2019 09:12
How to encode and pad texts for machine learning using Keras
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.preprocessing.text import hashing_trick
def preprocessing(questions, questions_max_length, vocabulary_size):
"""
Stateless preprocessing the text questions to a one-hot encoding and pads to max length questions.
The one-hot encodings max value is the vocabulary size.
The padding is attached at the end of each question up to the maximal question length.
@phisad
phisad / plotutils.py
Created March 15, 2019 14:09
Show many images on a grid like plot
from matplotlib import pyplot as plt
import numpy as np
def show_many(images, max_rows, max_cols, figsize=(20, 20), titles = None, titles_hspace=.1, plot_title = None):
fig = plt.figure(figsize=figsize, dpi=300)
for idx, image in enumerate(images):
row = idx // max_cols
col = idx % max_cols