我正在尝试使用自己的图像数据集进行预测,因此我将numpy数组转换为标准TensorFlow格式,但它给了我以下错误 预期的二进制或Unicode字符串,得到了数组([[[[126,115,117],[132,118,121],[121,106,109], 贝娄是我的代码, ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在使用pytest
对将数据拆分为机器学习问题的训练、验证和测试集进行测试。 我使用tmpdir_factory
创建临时文件,但它给我一个错误,比如TypeError: Expected binary or unicode string, got local('/tmp/pytest/pytest-4/test_folder0/train.tfrecord')
。 这是我的代码:
在conftest.py
:
DATA_FOLDER = 'test_folder'
@pytest.fixture(scope="session")
def train_dataset(tmpdir_factory):
return tmpdir_factory.mktemp(DATA_FOLDER).join('train.tfrecord')
@pytest.fixture(scope="session")
def val_dataset(tmpdir_factory):
return tmpdir_factory.mktemp(DATA_FOLDER).join('val.tfrecord')
@pytest.fixture(scope="session")
def test_dataset(tmpdir_factory):
return tmpdir_factory.mktemp(DATA_FOLDER).join('test.tfrecord')
在测试文件中:
def test_split(train_dataset, val_dataset, test_dataset):
# the arguments of split_function refer to the path where the splitting results is written
split_function(train_dataset, val_dataset, test_dataset)
"""continue with assert functions"""
有人可以帮忙吗? 谢谢
tmpdir_factory
夹具方法返回一个py.path.local对象,它封装了一个路径(有点pathlib.Path
)。 因此,可以将这些方法调用链接起来以操纵路径,就像在您的装置中使用mktemp().join()
所做的那样。 要从结果中取回str
路径,您必须明确地将py.path.local
转换为str
:
@pytest.fixture(scope="session")
def train_dataset(tmpdir_factory):
return str(tmpdir_factory.mktemp(DATA_FOLDER).join('train.tfrecord'))
当你的测试功能,不知道py.path.local
,通过转换创建的路径tmpdir_factory
回str
一般是使用这种灯具的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.