|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想请问一下在TensorFlow的dataset模块中有个map函数功能,我看论坛上都是直接调用编写好的函数,可是我在map之前已经写好了一个函数,为什么会提示没有函数的呢?
以下是我的代码,运行后报错了这个
TypeError: map() missing 1 required positional argument: 'map_func'
- import tensorflow as tf
- import numpy as np
- import os
- import gzip
- def load_data(data_folder):
- files = [
- 'train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz',
- 't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz'
- ]
- paths = []
- for fname in files:
- paths.append(os.path.join(data_folder,fname))
- with gzip.open(paths[0], 'rb') as lbpath:
- y_train = np.frombuffer(lbpath.read(), np.uint8, offset=8)
- with gzip.open(paths[1], 'rb') as imgpath:
- x_train = np.frombuffer(
- imgpath.read(), np.uint8, offset=16).reshape(len(y_train), 28, 28)
- with gzip.open(paths[2], 'rb') as lbpath:
- y_test = np.frombuffer(lbpath.read(), np.uint8, offset=8)
- with gzip.open(paths[3], 'rb') as imgpath:
- x_test = np.frombuffer(
- imgpath.read(), np.uint8, offset=16).reshape(len(y_test), 28, 28)
- return (x_train, y_train), (x_test, y_test)
- (train_X,trian_label),(test_X,test_label) = load_data('C:\\Users\\Administrator\\Desktop\\data')
- def func(x,y):
- x = np.expand_dims(x.astype(np.float32) / 255.0,axis = -1)
- return x,y
- dataset = tf.data.Dataset.map(func)
复制代码 |
|