Skip to content

Instantly share code, notes, and snippets.

@jasonsalas
jasonsalas / workerpools.go
Last active Jul 5, 2020
Using worker pools & buffered channels in Go
View workerpools.go
/* using worker pools & buffered channels in Go */
// h/t: Naveen Ramanathan @ golangbot.com
// https://golangbot.com/buffered-channels-worker-pools/
package main
import (
"fmt"
"math/rand"
"sync"
@jasonsalas
jasonsalas / depeche_mode_lyric_generator.py
Created Nov 20, 2019
Using a trained LSTM-based neural network model to generate Depeche Mode-style lyrics
View depeche_mode_lyric_generator.py
import numpy as np
import sys
from keras.models import Sequential
filename = 'trained_depechemode_lyrics_model.h5'
model = Sequential()
model.load_weights(filename)
model.compile(loss='categorical_crossentropy', optimizer='adam')
@jasonsalas
jasonsalas / depeche_mode_neuralnet.py
Created Nov 20, 2019
Generate Depeche Mode lyrics automatically with an LSTM neural network
View depeche_mode_neuralnet.py
import numpy as np
import sys
from keras.models import Sequential
from keras.layers import Dense, Dropout, LSTM
from keras.callbacks import ModelCheckpoint
from keras.utils import to_categorical
filename = 'dm_lyrics.txt'
raw_text = open(filename, 'r', encoding='utf-8').read()
raw_text = raw_text.lower()
@jasonsalas
jasonsalas / standalone_prediction_client.py
Last active Nov 5, 2019
NLP: predict the MPAA rating of a movie based solely on its plot summary
View standalone_prediction_client.py
# Make predictions on unseen data
#
# follows my full demo/repo at
# https://github.com/jasonsalas/nlp_predict_movie_rating_via_description/
import pickle
from keras.preprocessing.text import Tokenizer
from keras.models import load_model
''' Cabin in the Woods (R) '''
@jasonsalas
jasonsalas / app_keras.py
Created Oct 25, 2019
Server for deployed ML model in Flask
View app_keras.py
import os
import numpy as np
import tensorflow as tf
from keras.applications.vgg16 import preprocess_input, decode_predictions
from keras.models import load_model
from keras.preprocessing.image import img_to_array, load_img
from flask import Flask, redirect, url_for, request, render_template
# define a Flask app
app = Flask(__name__)
@jasonsalas
jasonsalas / get_model.py
Created Oct 25, 2019
Download pre-trained VGG16 model on ImageNet weights
View get_model.py
from keras.applications.vgg16 import VGG16
model = VGG16(weights='imagenet')
model.save('model_vgg16_imagenet.h5')
print('Pre-trained VGG16 model with ImageNet weights saved!')
@jasonsalas
jasonsalas / selfie_dcgan_client.py
Created Sep 7, 2019
Produce DCGAN's generator images from latent space
View selfie_dcgan_client.py
''' client to produce generator images from latent space '''
import numpy as np
from keras.models import load_model
MODEL = './generator_model_2800.h5'
z_noise = np.random.randn(100*25)
z_noise = z_noise.reshape(25, 100)
model = load_model(MODEL)
@jasonsalas
jasonsalas / dcgan_model.py
Created Sep 7, 2019
Model definition for shallow DCGAN
View dcgan_model.py
''' SHALLOW MODEL '''
img_shape = (32, 32, 3)
z_dim = 100
init = initializers.RandomNormal(mean=0.0, stddev=0.02)
opt = Adam(lr=0.0002, beta_1=0.5)
def build_discriminator(in_shape=img_shape):
model = Sequential()
model.add(Conv2D(64, (5,5), input_shape=in_shape, kernel_initializer=init))
@jasonsalas
jasonsalas / app.yaml
Created Feb 19, 2015
OAuth2 consumer for App Engine to access Pushbullet's API
View app.yaml
application: YOUR_APP_NAME_HERE
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: oauth.application
@jasonsalas
jasonsalas / CommonWaterVolumesActivity.java
Last active Aug 29, 2015
Android Wear Message API (wearable-to-handheld communication)
View CommonWaterVolumesActivity.java
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.wearable.view.WearableListView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;