simec
simec copied to clipboard
ValueError: tf.function-decorated function tried to create variables on non-first call. with non-zero orth_reg
Simple, relevant snippet of code
N_DIMS_EMBEDDING = 3
m_sim = np.array([(1.0, .7, .3),
(.7, 1.0, .2),
(.3, .2, 1.0)])
#define feature matrix - one-hot encoding
m_feat = np.array([(1.0, 0.0, 0.0),
(0.0, 1.0, 0.0),
(0.0, 0.0, 1.0)])
#compute the embedding
simec = SimilarityEncoder(m_sim.shape[0], N_DIMS_EMBEDDING, m_sim.shape[0], orth_reg=1.0)
simec.fit(m_feat, m_sim, epochs=1000)
It gives the error
ValueError: tf.function-decorated function tried to create variables on non-first call.
The error only happens when I set orth_reg in the SimilarityEncoder constructor.
This does not happen with older versions of Keras and Tensorflow.
For this error, I'm using:
Keras 2.4.2 Keras-Applications 1.0.8 Keras-Preprocessing 1.1.2
tensorflow 2.2.0 tensorflow-estimator 2.2.0
Yeah, simec.py was written quite a long time ago with older keras and tf versions. Then I switched to pytorch (--> simec_torch.py) and neglected the keras version.... I'll try to get everything to work with recent versions (I think it's mostly because tf & keras kind of merged) but it might be a while until I get to it - a pull request would be very welcome ;)