Open
Description
Hello,
I'm trying to get the output of the final layer from a model trained with Keras using tensorflow as backend. I'm using the tensorflowsharp with Unity.
I'm trying to access the last layer to get the final output, but i get this exception:
TFException: Shape [?,10] is not fully defined
[[Node: dense_one_input = Placeholder[dtype=DT_FLOAT, shape=[?,10], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
TensorFlow.TFStatus.CheckMaybeRaise (TensorFlow.TFStatus incomingStatus, System.Boolean last) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorFlow.TFSession.Run (TensorFlow.TFOutput[] inputs, TensorFlow.TFTensor[] inputValues, TensorFlow.TFOutput[] outputs, TensorFlow.TFOperation[] targetOpers, TensorFlow.TFBuffer runMetadata, TensorFlow.TFBuffer runOptions, TensorFlow.TFStatus status) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorFlow.TFSession+Runner.Run (TensorFlow.TFStatus status) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorflowBrain+<Predictor>c__Iterator0.MoveNext () (at Assets/Scripts/TensorflowBrain.cs:39)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
TensorflowBrain:Start() (at Assets/Scripts/TensorflowBrain.cs:17)
Keras Model:
model.add(Dense(40, input_dim=10, name="dense_one"))
model.add(Activation('relu'))
model.add(Dropout(dropout))
model.add(Dense(40, name="dense_two"))
model.add(Activation('relu'))
model.add(Dropout(dropout))
model.add(Dense(7, name="final", activation='softmax'))
model.compile(loss='sparse_categorical_crossentropy',
optimizer=adam,
metrics=['accuracy'])
C# Code:
using (var graph = new TFGraph())
{
tensor = new[] { 140.285470581055f, 41.11237678527829f, 5.836468505859f, 0.0f, 0.0f, 0.0f, 2.463f, 0.0f, 64.28699999999999f, 0.7287418126212261f };
if (tensor != null)
{
graph.Import(File.ReadAllBytes("Assets/TensorModel/" + modelFile));
var session = new TFSession(graph);
var runner = session.GetRunner();
runner.AddInput(graph["dense_one/kernel"][0], tensor);
runner.Fetch(graph["final/Softmax"][0]);
var output = runner.Run();
TFTensor results = output[0];
var re = (float[])results.GetValue(jagged: false);
for(int i = 0; i < re.Length; i++)
{
Debug.Log(re[i]);
}
}
}
I hope that you can help me. Thanks in advance.