Skip to content

Instantly share code, notes, and snippets.

Avatar

Philipp phisad

  • Berlin
View GitHub Profile
@phisad
phisad / plotutils.py
Created Mar 15, 2019
Show many images on a grid like plot
View plotutils.py
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
@phisad
phisad / text_sequence_preprocessing.py
Created Mar 15, 2019
How to encode and pad texts for machine learning using Keras
View text_sequence_preprocessing.py
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 / equals-code-template.xml
Last active Mar 13, 2019
Eclipse code template for equals hash toString with apache commons lang3
View equals-code-template.xml
${: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 / connected_graph.py
Created Mar 6, 2019
Keras disconnected graphs example when using multiple models
View connected_graph.py
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 / Tab.java
Created Feb 28, 2019
Primefaces 6.2 tabs with c:forEach
View Tab.java
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 / index.html
Created Jan 30, 2019
JSF welcome file for root context with redirect to landing page (somehow only HTML worked, but not XHTML)
View index.html
<?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 / tf-starter.py
Last active Jan 18, 2019
Tensorflow gpu starter (tensorflow-gpu 1.12 with CUDA 10.0)
View tf-starter.py
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)