我正在尝试实施最近的一篇论文。此实现的一部分涉及从 tf 1.14 迁移到 tf 2.1.0。该代码适用于 tf 1.14,但不再有效。
注意:如果我禁用急切执行,tf.compat.v1.disable_eager_execution()那么代码会按预期工作。
这是解决方案吗?我之前在TF 2.x 中制作了大量模型,并且从来没有禁用急切执行来实现正常功能。
我已将问题提炼为一个非常简短的要点,以显示正在发生的事情。
链接到要点 -- https://gist.github.com/darien-schettler/fd5b25626e9eb5b1330cce670bf9cc17
代码
# version 2.1.0
import tensorflow as tf
# version 1.18.1
import numpy as np
# ######## DEFINE CUSTOM FUNCTION FOR TF LAMBDA LAYER ######## #
def resize_like(input_tensor, ref_tensor):
""" Resize an image tensor to the same size/shape as a reference image tensor
Args:
input_tensor : (image tensor) Input image tensor that will be resized
ref_tensor : (image tensor) …Run Code Online (Sandbox Code Playgroud) machine-learning deep-learning tensorflow tf.keras tensorflow2.x
作为一些背景,我最近越来越关注 NLP 和文本处理。我对计算机视觉更加熟悉。我完全理解标记化的想法。
我的困惑源于Tokenizer可以在Tensorflow生态系统中找到的类的各种实现。
分别Tokenizer在Tensorflow Datasets( tfds) 和Tensorflow适当的: tfds.features.text.Tokenizer()& 中找到了一个类tf.keras.preprocessing.text.Tokenizer()。
我查看了源代码(链接如下),但无法收集任何有用的见解
这里的 tl;dr 问题是:您使用哪个库来做什么?一个图书馆比另一个图书馆有什么好处?
笔记
我一直在关注 Tensorflow In Practice Specialization以及本教程。TF in Practice Specialization 使用tf.Keras.preprocessing.text.Tokenizer()实现和文本加载教程使用tfds.features.text.Tokenizer()