I have one dataset with shape of (N_img,60,80,1) and 1 array of label created with tf.data.Dataset.from_tensor_slices. And now i want to split that into x_train and y_train with .map function but it gives me this error.
TypeError: in user code: TypeError: <lambda>() takes 1 positional argument but 2 were given
This is my code
img_width, img_height = 80, 60
n_positives_img, n_negatives_img = 17874, 26308
n_total_img = 44182
#Imports of datasets inside Drive
ds_negatives = np.loadtxt('/content/drive/MyDrive/Colab Notebooks/negative_depth.txt')
ds_positives = np.loadtxt('/content/drive/MyDrive/Colab Notebooks/positive_depth.txt')
#Labeled arrays for datasets
arrayceros = np.zeros(n_negatives_img)
arrayunos = np.ones(n_positives_img)
#Reshaping of datasets to convert separate them
arraynegativos= ds_negatives.reshape(( n_negatives_img, img_height, img_width,1))
arraypositivos= ds_positives.reshape((n_positives_img, img_height, img_width,1))
#Labeling datasets with the arrays
ds_negatives_target = tf.data.Dataset.from_tensor_slices((arraynegativos, arrayceros))
ds_positives_target = tf.data.Dataset.from_tensor_slices((arraypositivos, arrayunos))
#Concatenate 2 datasets and shuffle them
ds_concatenate = ds_negatives_target.concatenate(ds_positives_target)
datasetfinal = ds_concatenate.shuffle(n_total_img)
#24000 images for the training ds and 20000 for the validation ds
valid_ds_f = datasetfinal.take(20000)
train_ds_f = datasetfinal.skip(20000)
valid_ds = valid_ds_f.batch(12)
train_ds = train_ds_f.batch(12)
And this is what give me the error:
train_x_batches = train_ds.map(lambda x: x[0])
train_y_batches = train_ds.map(lambda x: x[1])
CodePudding user response:
Yes you have a dataset of tuples so the lambda function takes two arguments you can split the dataset in the following way
train_ds.map(lambda x, y: x)
train_ds.map(lambda x, y: y)