Skip to content

Issue with RationalHat layer, local variable 'LVinit' referenced before assignment #14

@RandomAnass

Description

@RandomAnass

When I use the layer "RationalHat", I get the following error:

UnboundLocalError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_33568/2646110522.py in
65 rho = tf.keras.Sequential([tf.keras.layers.Dense(1, activation="sigmoid")])
66 model = None
---> 67 model = PerslayModel(name="PersLay", diagdim=2, perslay_parameters=perslay_parameters, rho=rho)
68 model.compile(loss='binary_crossentropy',optimizer=optimizer,metrics=['accuracy'])
69 print(optimizer,perm_op,pweight,layer)

~\anaconda3\envs\downgrade\lib\site-packages\perslay\perslay.py in init(self, name, diagdim, perslay_parameters, rho)
159 LMinit, LRinit = plp["lmean_init"], plp["lr_init"]
160 LMiv = LMinit if not callable(LMinit) else LMinit([self.diagdim, plp["lnum"]])
--> 161 LRiv = LRinit if not callable(LRinit) else LVinit([1])
162 LM = tf.Variable(name=Lname+"-M", initial_value=LMiv, trainable=Ltrain)
163 LR = tf.Variable(name=Lname+"-R", initial_value=LRiv, trainable=Ltrain)

UnboundLocalError: local variable 'LVinit' referenced before assignment

When I checked the perslay.py file, I found :

elif layer == "RationalHat":
    LMinit, LRinit = plp["lmean_init"], plp["lr_init"]
    LMiv = LMinit if not callable(LMinit) else LMinit([self.diagdim, plp["lnum"]])
    LRiv = LRinit if not callable(LRinit) else LVinit([1])
    LM = tf.Variable(name=Lname+"-M", initial_value=LMiv, trainable=Ltrain)
    LR = tf.Variable(name=Lname+"-R", initial_value=LRiv, trainable=Ltrain)
    self.vars[nf].append([LM, LR])

Where LVinit is used before being defined, unlike the other layers where its defined at the beginning (after elif).

I dont know if I am not using the layer correctly (for example if I had to define an other layer before it). But I tried the same code with all the other layers (except the image layer) and it worked without an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions