Skip to content

Instantly share code, notes, and snippets.

View iamsurya's full-sized avatar

Surya Sharma iamsurya

View GitHub Profile
from keras import backend as K
import tensorflow as tf
frozen_graph = freeze_session(K.get_session(),
output_names=[out.op.name for out in model.outputs])
tf.train.write_graph(frozen_graph, "slopemodel", "slopemodel.pb", as_text=False)
# Define a function that takes a tensorflow session as input and freezes its model.
# Function from https://www.dlology.com/blog/how-to-convert-trained-keras-model-to-tensorflow-and-make-prediction/
def freeze_session(session, keep_var_names=None, output_names=None, clear_devices=True):
"""
Freezes the state of a session into a pruned computation graph.
Creates a new computation graph where variable nodes are replaced by
constants taking their current value in the session. The new graph will be
pruned so subgraphs that are not necessary to compute the requested
outputs are removed.
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Reshape
from keras.layers import Conv1D, MaxPooling1D
from keras.utils import np_utils
TIME_PERIODS = 21 # Number of steps in a time series sample
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=(21,)))
@iamsurya
iamsurya / keras2TF_preamble.py
Last active May 31, 2019 19:20
Keras2TF Example Preamble
# imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Load the data
df = pd.read_csv("slope-lownoise.txt", sep='\t', header=None)
labels = np.asarray(df[0]).reshape((len(df[0]),-1))
data = np.asarray(df.iloc[:,1:])
/*
Hello Mr. Raju Pengananapuram, please enter the velocity for MRover: 231.15
Please enter start time = 1
Please enter end time = 21
Please enter increment = 2
Results for distance calculation for MRover:
Time Distance Travelled (metres)
1 231.15
3 693.45
/*
Raju Pengananapuram looks at Sonik's program and finds it very useful.
However he realized that NASA's scientists want time to be between
1 seconds and 21 seconds with 2 second intervals (1, 3, 5... 21)
and the European Space Agency wants time between 30 and 180 seconds
with 30 second intervals (30, 60, 90... 180).
Recreate the program using while loops. Ask Raju for velocity, start time, end time
and interval.
/*
Raju Pengananapuram is a scientist from Chennai working in ISRO. His next project
is to create an algorithm for India's first Mars rover and has three days to do it.
However he also has to attend his brothers wedding in Trivendrum tomorrow.
He sits in his office worried. As he looks outside his window, he comes up with an idea.
He will ask one of his students, Sonik Sharma to help him with this work.
Your task is to calculate the distance the mars rover will travel given a velocity using
the formula distance = time * speed.
/* Author Sonik Sharma 26/2/2017
Hello World program
*/
/* Include files */
#include<iostream> /* includes cout cin */
#include<conio.h> /* conio = console io. includes getch = get character from keyboard */
/* My hello world program */
int main()
/* Author Sonik Sharma 26/2/2017
Program to ask the user for a number
then print its table from 1 to 10
*/
/* Include files */
#include<iostream> /* includes cout cin */
#include<conio.h> /* conio = console io. includes getch = get character from keyboard */
/* */
/* Author Sonik Sharma 26/2/2017
Program to ask the user for a number
then print its table from 1 to 10
*/
/* Include files */
#include<iostream> /* includes cout cin */
#include<conio.h> /* conio = console io. includes getch = get character from keyboard */
/* */