Ich versuche, eine Vorhersage auf einem Modell laufen auszuführen, die ich mit „Feintuning AlexNet mit TensorFlow“ https://kratzert.github.io/2017/02/24/finetuning-alexnet-with-tensorflow.htmlnicht Tensorflow Vorhersage in Java API
ich mit tf.saved_model.builder.SavedModelBuilder
in Python gespeichert das Modell trainiert und loaded das Modell in Java mit SavedModelBundle.load
. der Hauptteil des Codes ist:
SavedModelBundle smb = SavedModelBundle.load(path, "serve");
Session s = smb.session();
byte[] imageBytes = readAllBytesOrExit(Paths.get(path));
Tensor image = constructAndExecuteGraphToNormalizeImage(imageBytes);
Tensor result = s.runner().feed("input_tensor", image).fetch("fc8/fc8").run().get(0);
final long[] rshape = result.shape();
if (result.numDimensions() != 2 || rshape[0] != 1) {
throw new RuntimeException(
String.format(
"Expected model to produce a [1 N] shaped tensor where N is the number of labels, instead it produced one with shape %s",
Arrays.toString(rshape)));
}
int nlabels = (int) rshape[1];
float [] a = result.copyTo(new float[1][nlabels])[0];`
ich diese Ausnahme erhalten:
Exception in thread "main" java.lang.IllegalArgumentException: Sie einen Wert für Platzhalter Tensor füttern müssen ' Placeholder_1 'mit dtype float [[Knoten: Placeholder_1 = Placeholder_output_shapes = [[]], dtype = DT_FLOAT, shape = [], _device = "/ job: localhost/replik: 0/task: 0/cpu: 0"]]
Ich sah, dass der Code oben arbeitete für einige Leute, und ich kann nicht herausfinden, was hier fehlt. Beachten Sie, dass das Netz mit den Knoten "input_tensor" und "fc8/fc8" vertraut ist, da es nicht sagt, dass es sie nicht kennt.