Error using Keras-like TimeDistributed with Dense layer

16 views
Skip to first unread message

Phuong LE-HONG

unread,
Jan 1, 2023, 7:49:25 AM1/1/23
to BigDL User Group
Dear all,

I'm working with Keras layers in BigDL 2.1.0. I have a problem applying the TimeDistributed to a Dense layer. It raises a type mismatch error:

---
error: type mismatch;
 found   : com.intel.analytics.bigdl.dllib.keras.layers.Dense[Float]
 required: com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer[com.intel.analytics.bigdl.dllib.nn.abstractnn.Activity,com.intel.analytics.bigdl.dllib.tensor.Tensor[Float],Float]
Note: com.intel.analytics.bigdl.dllib.tensor.Tensor[Float] <: com.intel.analytics.bigdl.dllib.nn.abstractnn.Activity (and com.intel.analytics.bigdl.dllib.keras.layers.Dense[Float] <: com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer[com.intel.analytics.bigdl.dllib.tensor.Tensor[Float],com.intel.analytics.bigdl.dllib.tensor.Tensor[Float],Float]), but class KerasLayer is invariant in type A.
You may wish to define A as +A instead. (SLS 4.5)
---

Here is the main code:

===
import com.intel.analytics.bigdl.numeric.NumericFloat
import com.intel.analytics.bigdl.dllib.keras.layers._
import com.intel.analytics.bigdl.dllib.keras.Model

val td = TimeDistributed(Dense(outputDim = 5))
===

I tried to replace Keras-like Dense with BigDL-Dense, or Keras-like TimeDistributed with BigDL-TimeDistributed, but it did not work either. 

How should I fix this error? It's great if we have an usage example but I did not find any on the web.

Btw, the latest documentation on ReadTheDocs seems not to be updated with the latest code. There is not any documentation on TimeDistributed. 


Thank you very much.

Phuong

Phuong LE-HONG

unread,
Jan 2, 2023, 10:49:16 AM1/2/23
to BigDL User Group
Hello,

Well, I have the same problem applying Keras-like TimeDistributed to many layers, not only Dense as in the previous email. It seem that TimeDistributed wants a 

KerasLayer[Activity, Tensor[T], T] 

but the Dense layer is of type KerasLayer[Tensor[T], Tensor[T], T] 

Tensor[T] is Activity but the types are mismatched. 

===
class TimeDistributed[T: ClassTag](
  val layer: KerasLayer[Activity, Tensor[T], T],
  val inputShape: Shape = null)(implicit ev: TensorNumeric[T])
extends KerasLayer[Activity, Tensor[T], T]
===

Can anyone tell me how I can work around this? Is there any working example of Keras-like TimeDistributed in BigDL?

Thank you for your help.

Phuong

Jennie Wang

unread,
Jan 3, 2023, 7:37:32 PM1/3/23
to User Group for BigDL
Hi Phuong,

Sorry to hear you getting this error. We'll add API doc and example of TimeDistributed layer in BigDL soon. 
You may need to manually cast Dense to KerasLayer[Activity, Tensor[Float], Float] , then pass to TimeDistributed layer.

Thanks,
Jennie

Phuong LE-HONG

unread,
Jan 4, 2023, 1:07:39 AM1/4/23
to Jennie Wang, User Group for BigDL
Dear Jennie,

Thanks for your reply. Yes, I had to cast the layer to KerasLayer[Activity, Tensor[Float], Float] as you suggested and overcome the problem. I think that we should add an additional constructor to TimeDistributed to avoid this manual work.

Best,

Phuong

--
You received this message because you are subscribed to the Google Groups "User Group for BigDL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/ce143397-ec3f-4daa-952e-116ad4501bb3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages