bottler / iisignature

Iterated integral signature calculations
MIT License
94 stars 18 forks source link

RuntimeError: I have received an input which is not from iisignature.prepare() #5

Closed kccheung closed 5 years ago

kccheung commented 5 years ago

I received the below Runtime error when I used the below keras model with LogSig layer from iisignature_tensorflow.py in examples folder:

    model = Sequential()
    model.add(InputLayer(input_shape=input_shape))
    model.add(Lambda(lambda x: LogSig(x, SIG_LEVEL), output_shape=(FEATURE_DIM,)))
    # model.add(BatchNormalization())
    model.add(Dense(1, activation='linear'))
UnknownError (see above for traceback): RuntimeError: I have received an input which is not from iisignature.prepare()
Traceback (most recent call last):

  File "/home/support/.pyenv/versions/va-worker-3.6.6/lib/python3.6/site-packages/tensorflow/python/ops/script_ops.py", line 158, in __call__
    ret = func(*args)

  File "/app/powerarena_defond/utils/iisignature_tensorflow.py", line 72, in __call__
    return iisignature.logsig(x,self.s,self.method)

RuntimeError: I have received an input which is not from iisignature.prepare()

     [[Node: lambda_1/LogSig = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], _gradient_op_type="PyFuncGrad55521845", token="pyfunc_0", _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_input_1_0_2)]]
bottler commented 5 years ago

There's an initialisation/precalculation step before you do a log signature calculation, and you pass its result to LogSig (like the logsig function in iisignature). LogSig doesn't expect a number as its second argument, hence the error. Somewhere, perhaps before all this, you need to do

s = iisignature.prepare(input_shape[-1],SIG_LEVEL)

(where input_shape[-1] is whatever your dimension is).

Then replace the Lambda layer with

model.add(Lambda(lambda x: LogSig(x, s), output_shape=(FEATURE_DIM,)))

.

By the way, it looks like you've taken something which was working with Sig and changed it to LogSig. If that's the case, note that the output_shape will need to change. For example a calculation might need to change from iisignature.siglength to iisignature.logsiglength.

kccheung commented 5 years ago

Thank you. I fixed it according to your instruction.