0

我正在通过转换为缓冲区类型为线性学习器准备数据,如本示例MNIST 线性学习器中所示

buf = io.BytesIO
smac.write_numpy_to_dense_tensor(buf, features_train, target_train)
buf.seek(0)
print(buf)
boto3.resource('s3').Bucket(bucket).Object(os.path.join(prefix, 
                                           train_location)).upload_fileobj(buf)

但是,当我尝试将转换后的数据上传到 S3 时,出现以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-54-4ffe1a2f757c> in <module>()
      4 import boto3
      5 import os
----> 6 upload_train_data_to_s3(features_train, target_train, prefix, bucket)

<ipython-input-53-cb779ecf0f0a> in upload_train_data_to_s3(features_train, target_train, prefix, bucket, train_location, val_location)
      3     """Upload training and validation set to S3"""
      4     buf = io.BytesIO
----> 5     smac.write_numpy_to_dense_tensor(buf, features_train, target_train)
      6     buf.seek(0)
      7     print(buf)

~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/amazon/common.py in write_numpy_to_dense_tensor(file, array, labels)
    108         if labels is not None:
    109             _write_label_tensor(resolved_label_type, record, labels[index])
--> 110         _write_recordio(file, record.SerializeToString())
    111 
    112 

~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/amazon/common.py in _write_recordio(f, data)
    177     """Writes a single data point as a RecordIO record to the given file."""
    178     length = len(data)
--> 179     f.write(struct.pack('I', _kmagic))
    180     f.write(struct.pack('I', length))
    181     pad = (((length + 3) >> 2) << 2) - length

TypeError: descriptor 'write' requires a '_io.BytesIO' object but received a 'bytes'

我遵循与示例相同的步骤,包括类型转换为 float32 但没有运气。感谢您帮助解决此问题。

4

0 回答 0