试图将Tensorflow训练的模型加载到Deeplearning4J中,出现以下错误。
IllegalStateException: Invalid array shape: cannot associate an array with shape [38880] with a placeholder of shape [-1, -1, -1, 3]:shape is wrong rank or does not match on one or more dimensions
var arr: INDArray = Nd4j.create(data) //.reshape(1, -1, -1, 3);
arr = Nd4j.pile(arr, arr)
sd.associateArrayWithVariable(arr, sd.variables.get(0))
Python模型是这样加载的。
# Load image using OpenCV and
# expand image dimensions to have shape: [1, None, None, 3]
# i.e. a single-column array, where each item in the column has the pixel RGB value
image = cv2.imread(PATH_TO_IMAGE)
image_expanded = np.expand_dims(image, axis=0)
有什么问题请知道的朋友解释一下。
1)Python数组中的[1,None,None,3]是什么意思?
2) 在Python中,np.expand_dims(image, axis=0)是什么意思?
3) Deeplearning4J reshape(1, -1, -1, 3)。
你在这里混合了两个不同的概念,TF占位符和命令式的numpy-like reshape。
在你的例子中,模型期望4D输入张量,形状为[-1, -1, -1, 3]。对于人类来说,它可以被翻译成[Any, Any, Any, 3]。但你试图用形状为[38880],等级为1的张量来输入。
现在回答你的问题。
1) 见上面。-1被视为 "Any"。
2) 这个函数将1加为维度。例如,如果你有[38880],在axis=0时expand_dims将使其成为[1, 38880]。
3)不,那是错误的。你不应该用这个作为你的形状。你有一些图像,所以你应该指定你的图像有适当的尺寸,即[1,800,600,3]。