Dear Kai,
Thanks for your reply. I still have difficulty wrapping the MapTable. Here is my problem. Say I have a table of 10 elements, each is a tensor of shape 1 x 5 x 4. I'd like to apply a GRU(3) to each element to get a tensor of shape 1 x 3. After that, all the states are concatenated/merged to get the final tensor of shape 10 x 3.
The code I am using is as follows:
val gru = GRU(3)
val mapTableGRU = MapTable(gru)
val mapTableGRUKeras = new KerasLayerWrapper[Float](mapTableGRU.asInstanceOf[AbstractModule[Activity, Activity, Float]])
mapTableGRUKeras.build(KerasUtils.addBatch(Shape(1, 5, 4)))
val mtgNode = mapTableGRUKeras.inputs(split) // point to the SplitTensor node which provides a table with 10 elements
===
The build() method raises the error:
[E] Exception in thread "main" com.intel.analytics.bigdl.dllib.utils.UnKnownException: MapTable[e9f43ef2]{
[E] GRU[3e10a1f]
[E] }
[E] com.intel.analytics.bigdl.dllib.tensor.DenseTensor cannot be cast to com.intel.analytics.bigdl.dllib.utils.Table
[E] at com.intel.analytics.bigdl.dllib.utils.Log4Error$.unKnowExceptionError(Log4Error.scala:60)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.AbstractModule.forward(AbstractModule.scala:295)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward$.computeOutputShape(KerasLayerWrapper.scala:93)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward.computeOutputShape(KerasLayerWrapper.scala:46)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build(InferShape.scala:76)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build$(InferShape.scala:75)
[E] at com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer.build(KerasLayer.scala:316)
===
I think that there is something wrong with the input shape to the MapTable wrapper here but I have not found the problem yet. The SplitTensor node gives me a table.
I tried to build() the gru instead of the wrapper, as follows:
val gru = GRU(3)
gru..build(KerasUtils.addBatch(Shape(5, 4)))
val mapTableGRU = MapTable(gru)
val mapTableGRUKeras = new KerasLayerWrapper[Float](mapTableGRU.asInstanceOf[AbstractModule[Activity, Activity, Float]])
// mapTableGRUKeras.build(KerasUtils.addBatch(Shape(1, 5, 4)))
val mtgNode = mapTableGRUKeras.inputs(split) // point to the SplitTensor node which provides a table with 10 elements
The the last line raises a different error:
[E] Exception in thread "main" com.intel.analytics.bigdl.dllib.utils.InvalidOperationException: Recurrent: input should be a 3D/5D/6D Tensor, e.g [batch, times, nDim], current input.dim = 4
[E] at com.intel.analytics.bigdl.dllib.utils.Log4Error$.invalidOperationError(Log4Error.scala:38)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.AbstractModule.forward(AbstractModule.scala:291)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward$.computeOutputShape(KerasLayerWrapper.scala:93)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward.computeOutputShape(KerasLayerWrapper.scala:46)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build(InferShape.scala:76)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build$(InferShape.scala:75)
[E] at com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer.build(KerasLayer.scala:316)
[E] at com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer.inputs(KerasLayer.scala:333)
It's not easy to wrap a MapTable, I think. Should the Keras-style MapTable be added to the next version of BigDL?
Thanks for your advice.
Phuong