Search code examples
kerassplitdeep-learningtensorflow-datasetsmnist

ValueError: unpack: when trying to split fashion_mnist into 3 splits


(train_dataset,validation_dataset,test_dataset) = tfds.load('fashion_mnist',
                            with_info=True, as_supervised=True,
                            split=['train[:80%]', 'train[80%:90%]', 'train[90%:]'])

I am trying to split the fashion_mnist into 3 sets-train test and validation. I'm not sure what the error is here as i am simply not able to resolve it.


Solution

  • The "fashion_mnist" dataset only has a train and a test split in Tensorflow Datasets (see documentation, Splits section), so in the split paramter it expects a list that has length at most 2, however you are using a list of length 3. In order to get a train, validation and test split, you could do the following:

    whole_ds,info_ds = tfds.load("fashion_mnist", with_info = True, split='train+test', as_supervised=True)
    
    n = tf.data.experimental.cardinality(whole_ds).numpy() # 70 000
    train_num = int(n*0.8)
    val_num = int(n*0.1)
    
    train_ds = whole_ds.take(train_num)
    val_ds = whole_ds.skip(train_num).take(val_num)
    test_ds = whole_ds.skip(train_num+val_num)