CS663 | computer vision
  • outline
  • projects
  • syllabus
  • links

Comparing Tensorflow w/Keras

 

 

 

Tensroflow and Keras

While you can create networs with Tensorflow in this class we will use the framework that sits on top called Keras to create our networks and is official in Tensorflow and its use is encouraged.


 

 

with KERAS an example

Well, this is how you would do the following model (plain NN) using the sequential model paradigm in Keras:

from keras.models import Sequential
from keras.layers import Dense, Activation

model = Sequential([
Dense(10, input_shape=(10,)),
Activation('relu'),
Dense(8),
Activation('relu'),
Dense(4),
Activation('softmax'),
])
  • The first two lines of code import the Sequential model and the Dense and Activation layers, respectively. A Dense layer is a fully connected neural network, whereas an Activation layer is a very specific way of invoking a rich set of activation functions, such as ReLU and SoftMax, as in the previous example (these will be explained in detail later).

 

Alternative Keras

from keras.models import Sequential
from keras.layers import Dense, Activation

model = Sequential()
model.add(Dense(10, input_dim=10))
model.add(Activation('relu'))
model.add(Dense(8))
model.add(Activation('relu'))
model.add(Dense(4))
model.add(Activation('softmax'))

 

Now Using the Keras "Functional API" Alternative

from keras.layers import Input, Dense
from keras.models import Model

inputs = Input(shape=(10,))

x = Dense(10, activation='relu')(inputs)
x = Dense(8, activation='relu')(x)
y = Dense(4, activation='softmax')(x)

model = Model(inputs=inputs, outputs=y)

 

cs663:computer vision

  • home
  • outline
  • projects
  • syllabus
  • links