tfds split在python 3和tensorflow 2中抛出AssertionError。

问题描述 投票:1回答:1

当我把运行时切换到python 2时,下面这段代码可以正常运行。但是在python 3中,它给我一个错误。

test, train = tfds.Split.TRAIN.subsplit([1, 8])

train_set_raw = tfds.load("tf_flowers", split=train, as_supervised=True)
test_set_raw = tfds.load("tf_flowers", split=test, as_supervised=True)

subsplit([1, 8]) 2 ----> 3 test_set_raw = tfds.load("tf_flowers", split=train_split, as_supervised=True) 4 valid_set_raw = tfds.load("tf_flowers", split=valid_split, as_supervised=True)

11帧 usrlocallibpython3.6dist-packagestensorflow_datasetscoretfrecords_reader.py 中 _str_to_relative_instruction(spec) 277 res = _SUB_SPEC_RE.match(spec) 278 if not res: --> 279 raise AssertionError('Unrecognized instruction format: %s' % spec) 280 unit = '%' if res.group('from_pct') or res.group('to_pct') else 'abs' 281 return ReadInstruction(

断言错误。未识别的指令格式.NamedSplit('train')(tfds.percent[11:100]) NamedSplit('train')(tfds.percent[11:100])

python python-3.x tensorflow tensorflow-datasets
1个回答
1
投票

请参考下面的代码,它可以根据你的要求分割tfds数据集。

%tensorflow_version 2.x

import tensorflow as tf
import tensorflow_datasets as tfds

print(tfds.__version__)
print(tf.__version__)

(raw_test, raw_test), metadata = tfds.load(
'tf_flowers',
split=['train[:11%]', 'train[11%:100%]'],
with_info=True,
as_supervised=True)

输出。

2.1.0
2.2.0-rc3
'\nSPLIT_WEIGHTS = (8, 1)
 \nsplits = tfds.Split.TRAIN.subsplit(weighted=SPLIT_WEIGHTS)
 \n(raw_train, raw_test), metadata = tfds.load(name="tf_flowers",with_info=True,split=list(splits))\n'

希望对你有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.