tf-keras functions doesn't work
maifeeulasad opened this issue ยท 4 comments
I was trying to generate latex quickly from my python code, but it didn't return the output as expected.
Code:
import latexify
import tensorflow.keras.backend as K
@latexify.with_latex
def dice_coef(y_true, y_pred, smooth = 1):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
print(dice_coef)
dice_coef
@maifeeulasad Thanks for reporting the issue!
Since the current implementation is different from the released version(v0.1.1), I also tried the function above using the main:
I guess some problems are already fixed (in main), but following things are still remaining:
- Long name variables: Tracked by #82.
- The prefix
K
: I think we need some additional config to inform about prefixes that should be trimmed.
Note that Latexify can't recognize import aliases by only seeing the wrapped function due to the limitation of parsing. We hard-coded automated trimming for only math
, numpy
, and np
, but increasing the number of hard-coded prefixes (especially trivial names like K
) may be unsafe.
I also think automatically collecting imported modules through globals()
could work. Let me make another issue for it.
Awesome. Eagerly waiting for the updated version.
Will use main
branch of this repo to generate latex for now.
FYI: v0.2.0 has been released. I'd close this issue, but feel free to reopen it if you have more questions.