Skip to content

Instantly share code, notes, and snippets.

@robertlugg
Created August 3, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertlugg/8f17314c1b0f79edaded60b3aaada067 to your computer and use it in GitHub Desktop.
Save robertlugg/8f17314c1b0f79edaded60b3aaada067 to your computer and use it in GitHub Desktop.
from tensorflow import keras
import numpy as np
from IPython import embed
INPUT_SHAPE = (3, 3, 1)
CONV_SIZE = 3
model_name = 'test_model'
def create_model():
sub_image = keras.layers.Input(shape=INPUT_SHAPE, name="image")
c2d=keras.layers.Conv2D(1, (CONV_SIZE, CONV_SIZE), use_bias=False, name="C2D")(sub_image)
output = keras.layers.Dense(1, name="action",use_bias=False,trainable=False)(c2d)
model = keras.models.Model(inputs=sub_image, outputs=output, name=model_name)
return model
input = np.ones((1, 3, 3, 1), dtype=np.float)
embed()
model = create_model()
result = model(input)
hl1_weights = model.layers[1].get_weights()
print(np.sum(hl1_weights))
hl2_weights = model.layers[2].get_weights()
print(np.sum(hl2_weights))
print(np.sum(hl1_weights) * np.sum(hl2_weights))
print(f'tf run sum={result}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment