Код: Выделить всё
dataset = tf.data.experimental.make_csv_dataset(csv_path,
label_name=label,
batch_size=128,
num_epochs=1,
shuffle=True,
shuffle_buffer_size=1000)
def preprocess(features, label):
preprocessed_features = {}
for name, feature in features.items():
if feature.dtype == 'string':
encoder = layers.StringLookup(output_mode='one_hot')
encoder.adapt(feature)
preprocessed_features[name] = encoder(feature)
elif feature.dtype == 'int':
normalizer = layers.Normalization(output_mode='one_hot')
normalizer.adapt(feature)
preprocessed_features[name] = normalizer(feature)
return preprocessed_features, label
dataset = dataset.map(preprocess)
Код: Выделить всё
OperatorNotAllowedInGraphError: in user code:
File "C:\Users\User\AppData\Local\Temp\4\ipykernel_7508\1668558205.py", line 8, in preprocess *
encoder.adapt(feat[name])
File "c:\Users\User\Spark\spark_env\Lib\site-packages\keras\src\layers\preprocessing\string_lookup.py", line 368, in adapt **
super().adapt(data, steps=steps)
File "c:\Users\User\Spark\spark_env\Lib\site-packages\keras\src\layers\preprocessing\index_lookup.py", line 582, in adapt
self.finalize_state()
File "c:\Users\User\Spark\spark_env\Lib\site-packages\keras\src\layers\preprocessing\index_lookup.py", line 626, in finalize_state
if self._has_input_vocabulary or tf.equal(self.token_counts.size(), 0):
OperatorNotAllowedInGraphError: Using a symbolic `tf.Tensor` as a Python `bool` is not allowed. You can attempt the following resolutions to the problem: If you are running in Graph mode, use Eager execution mode or decorate this function with @tf.function. If you are using AutoGraph, you can try decorating this function with @tf.function. If that does not work, then you may be using an unsupported feature or your source code may not be visible to AutoGraph. See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/autograph/g3doc/reference/limitations.md#access-to-source-code for more information.
Код: Выделить всё
[(feat, label)] = dataset.take(1)
def preprocess(features, label):
preprocessed_features = {}
for name, feature in features.items():
if feature.dtype == 'string':
encoder = layers.StringLookup(output_mode='one_hot')
encoder.adapt(feat[name])
preprocessed_features[name] = encoder(feature)
elif feature.dtype == 'int':
normalizer = layers.Normalization(output_mode='one_hot')
normalizer.adapt(feat[name])
preprocessed_features[name] = normalizer(feature)
return preprocessed_features, label
dataset.map(preprocess)
И пока мы этим занимаемся, каким может быть оптимальный способ (желательно без использования панд) построить конвейеры ввода и предварительной обработки, которые могут работать асинхронно с пакетами данных? data, если данные слишком велики для хранения в памяти (у меня нет, но я могу столкнуться с такой ситуацией в будущем)?
Я планирую сохранить модель предварительной обработки и модели обучения отделены друг от друга (поскольку tf docs — это лучший способ предварительной обработки категориальных признаков).
Подробнее здесь: https://stackoverflow.com/questions/791 ... processing
Мобильная версия