使用tensorflow示例从谷歌云存储加载.npy文件

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

我正在尝试从我的谷歌云存储中加载.npy文件到我的模型我跟着这个例子在这里Load numpy array in google-cloud-ml job但我得到这个错误

'utf-8'编解码器无法解码位置0的字节0x93:无效的起始字节

你能帮我吗 ??这是代码中的示例

Here i read the file

with file_io.FileIO(metadata_filename, 'r') as f:
    self._metadata = [line.strip().split('|') for line in f]

and here i start processing on it

if self._offset >= len(self._metadata):
    self._offset = 0
    random.shuffle(self._metadata)
meta = self._metadata[self._offset]
self._offset += 1
text = meta[3]
    if self._cmudict and random.random() < _p_cmudict:
        text = ' '.join([self._maybe_get_arpabet(word) for word in text.split(' ')])

    input_data = np.asarray(text_to_sequence(text, self._cleaner_names), dtype=np.int32)
    f = StringIO(file_io.read_file_to_string(
        os.path.join('gs://path',meta[0]))
    linear_target = tf.Variable(initial_value=np.load(f), name='linear_target')
    s = StringIO(file_io.read_file_to_string(
        os.path.join('gs://path',meta[1])))
    mel_target = tf.Variable(initial_value=np.load(s), name='mel_target')
    return (input_data, mel_target, linear_target, len(linear_target))

and this is a sample from the data sample

python-3.x numpy tensorflow google-cloud-ml
1个回答
2
投票

这可能是因为您的文件不包含utf-8编码文本。

可能的情况是,您可能需要使用mode ='rb'将file_io.FileIO实例初始化为二进制文件,或者在调用read_file_to_string时设置binary_mode = True。

这将导致读取的数据作为字节序列而不是字符串返回。

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