Home > Blockchain >  How to zip images to images as targets in tf.data.Dataset
How to zip images to images as targets in tf.data.Dataset

Time:07-14

I'm trying to train an CNN autoencoder model on a pretty big dataset so I'm using tf.data.Dataset. I've been trying to zip the train images to themselves so that I can use the images themselves as targets. I tried doing is like this:

train_dataset_target = tf.keras.preprocessing.image_dataset_from_directory(BASE_TRAIN 
,label_mode=None,batch_size=64, image_size = (96, 96))
train_dataset_images = tf.keras.preprocessing.image_dataset_from_directory(BASE_TRAIN 
,label_mode=None,batch_size=64, image_size = (96, 96))
train_dataset = tf.data.Dataset.zip((train_dataset_images, train_dataset_target))

And also like this:

train_dataset_target = tf.keras.preprocessing.image_dataset_from_directory(BASE_TRAIN 
,label_mode=None,batch_size=64, image_size = (96, 96))
train_dataset = tf.data.Dataset.zip((train_dataset_target, train_dataset_target))

This, however, resulted in a huge loss both times so I visualized couple of examples to see what's the deal. As it turned out, images are not correctly mapped and I'm not sure how to fix that. Any tips?

Edit: As it was requested, here is that print(next(iter(train_dataset.take(1)))) produces:

(<tf.Tensor: shape=(64, 96, 96, 3), dtype=float32, numpy=
array([[[[ 23.918022  ,  26.30344   ,  14.074273  ],
     [ 24.361654  ,  26.74707   ,  14.517903  ],
     [ 23.715603  ,  26.10102   ,  13.871853  ],
     ...,
     [ 43.131763  ,  26.131763  ,  16.131763  ],
     [ 46.355305  ,  29.355307  ,  19.355307  ],
     [ 41.15631   ,  26.578156  ,  16.763157  ]],

    [[ 21.554363  ,  22.716959  ,   4.4814453 ],
     [ 19.994629  ,  21.350586  ,   2.463379  ],
     [ 23.771809  ,  25.584797  ,   5.157226  ],
     ...,
     [ 38.281742  ,  24.3125    ,  15.        ],
     [ 38.958496  ,  25.802246  ,  16.489746  ],
     [ 42.488426  ,  29.332176  ,  20.27195   ]],

    [[ 44.6021    ,  44.6021    ,  18.098955  ],
     [ 46.815266  ,  46.815266  ,  19.887207  ],
     [ 52.252987  ,  52.252987  ,  24.32059   ],
     ...,
     [ 40.21609   ,  30.359264  ,  20.325459  ],
     [ 39.332844  ,  29.796873  ,  20.796873  ],
     [ 38.908302  ,  29.908302  ,  20.908302  ]],

    ...,

    [[ 64.59651   ,  71.6835    ,  29.318817  ],
     [ 59.916687  ,  66.978226  ,  25.360334  ],
     [ 53.713356  ,  59.82009   ,  21.497223  ],
     ...,
     [109.53851   , 106.53851   ,  89.53851   ],
     [115.37259   , 112.37259   ,  95.37259   ],
     [112.60654   , 109.60654   ,  92.60654   ]],

    [[ 89.68636   ,  93.06136   ,  60.84261   ],
     [ 95.50537   ,  98.39258   ,  67.149414  ],
     [ 95.82389   ,  98.35514   ,  67.82389   ],
     ...,
     [134.62599   , 133.46974   , 113.313484  ],
     [132.64404   , 131.4878    , 111.33154   ],
     [132.15625   , 131.        , 110.84375   ]],

    [[128.258     , 128.258     , 102.25799   ],
     [127.007034  , 127.007034  , 101.007034  ],
     [125.637     , 125.637     ,  99.637     ],
     ...,
     [138.79515   , 136.79515   , 115.02434   ],
     [139.58838   , 137.58838   , 115.817566  ],
     [140.47763   , 138.47763   , 115.71452   ]]],


   [[[ 13.833333  ,  13.833333  ,  13.833333  ],
     [ 13.666666  ,  13.666666  ,  13.666666  ],
     [ 13.666666  ,  13.666666  ,  13.666666  ],
     ...,
     [ 17.742188  ,  17.742188  ,  17.742188  ],
     [ 17.265625  ,  17.265625  ,  17.265625  ],
     [ 19.481771  ,  20.325521  ,  19.903646  ]],

    [[  9.        ,   9.        ,   9.        ],
     [  9.        ,   9.        ,   9.        ],
     [  9.        ,   9.        ,   9.        ],
     ...,
     [ 17.5       ,  17.5       ,  17.5       ],
     [ 17.632812  ,  17.632812  ,  17.632812  ],
     [ 18.789062  ,  19.632812  ,  19.210938  ]],

    [[ 11.        ,  11.        ,  11.        ],
     [ 11.9557295 ,  11.9557295 ,  11.9557295 ],
     [ 12.        ,  12.        ,  12.        ],
     ...,
     [ 21.851562  ,  21.851562  ,  21.851562  ],
     [ 22.        ,  22.        ,  22.        ],
     [ 21.507812  ,  22.351562  ,  21.929688  ]],

    ...,

    [[  1.1668091 ,   6.018424  ,   9.518485  ],
     [  0.46620274,   4.3542995 ,  10.023627  ],
     [  0.31514263,   2.497552  ,  10.648639  ],
     ...,
     [ 93.25734   ,  64.57512   ,  36.960796  ],
     [ 92.95539   ,  63.400787  ,  37.25782   ],
     [ 89.5597    ,  59.393135  ,  32.39338   ]],

    [[ 85.71094   ,  97.21094   , 120.21094   ],
     [ 87.10156   ,  98.60156   , 121.60156   ],
     [ 91.5625    , 103.0625    , 126.0625    ],
     ...,
     [117.33594   , 110.83594   , 110.05469   ],
     [118.39844   , 111.63281   , 112.765625  ],
     [120.47656   , 112.97656   , 114.47656   ]],

    [[ 92.33331   , 108.16666   , 124.80724   ],
     [ 91.765594  , 104.72133   , 122.18745   ],
     [ 88.73424   , 101.71601   , 119.10401   ],
     ...,
     [175.3202    , 184.82018   , 163.5025    ],
     [178.28647   , 187.78644   , 166.72919   ],
     [190.29189   , 199.79185   , 179.13564   ]]],


   [[[136.4796    , 147.02127   , 149.02127   ],
     [135.67708   , 146.21875   , 148.21875   ],
     [135.45009   , 145.99174   , 147.99174   ],
     ...,
     [239.9041    , 146.93533   , 171.61241   ],
     [241.89714   , 145.9323    , 169.0664    ],
     [242.08333   , 145.45833   , 168.        ]],

    [[130.625     , 137.5       , 140.875     ],
     [130.72656   , 137.60156   , 140.97656   ],
     [131.97527   , 138.85027   , 142.22527   ],
     ...,
     [237.64717   , 150.75      , 173.6289    ],
     [241.92188   , 151.04688   , 173.67188   ],
     [242.125     , 151.25      , 172.14583   ]],

    [[154.07074   , 159.07074   , 165.07074   ],
     [153.86458   , 158.86458   , 164.86458   ],
     [155.1354    , 160.1354    , 166.1354    ],
     ...,
     [248.61504   , 165.64627   , 187.32335   ],
     [249.64714   , 163.80598   , 183.61848   ],
     [248.42708   , 162.0104    , 181.0104    ]],

    ...,

    [[  5.166626  ,   4.166626  ,   0.8749695 ],
     [  5.742155  ,   4.742155  ,   1.162734  ],
     [  7.0629206 ,   6.0629206 ,   2.0629206 ],
     ...,
     [249.78085   , 241.32336   ,  48.229248  ],
     [255.        , 242.63927   ,  61.369778  ],
     [243.9404    , 223.47725   ,  51.194305  ]],

    [[  3.5       ,   5.5       ,   1.25      ],
     [  3.90625   ,   5.90625   ,   1.5039062 ],
     [  4.7539062 ,   6.7539062 ,   1.875     ],
     ...,
     [254.23828   , 244.74867   ,  63.529976  ],
     [251.95703   , 227.65234   ,  60.171875  ],
     [228.58456   , 190.94785   ,  32.588474  ]],

    [[ 45.688103  ,  47.688103  ,  42.6881    ],
     [ 46.89685   ,  48.89685   ,  43.89685   ],
     [ 48.45112   ,  50.45112   ,  45.45112   ],
     ...,
     [254.65016   , 234.57927   ,  66.06678   ],
     [240.5571    , 196.00754   ,  44.132603  ],
     [214.19675   , 154.57162   ,  13.123365  ]]],


   ...,


   [[[198.8639    , 199.8639    , 191.8639    ],
     [198.09895   , 199.09895   , 191.09895   ],
     [198.09895   , 199.09895   , 191.09895   ],
     ...,
     [189.7552    , 190.7552    , 182.7552    ],
     [187.90625   , 188.90625   , 180.90625   ],
     [187.        , 188.        , 180.        ]],

    [[197.25203   , 198.95515   , 188.84578   ],
     [197.        , 198.70312   , 188.59375   ],
     [197.        , 198.70312   , 188.59375   ],
     ...,
     [189.7552    , 190.7552    , 182.7552    ],
     [187.90625   , 188.90625   , 180.90625   ],
     [187.        , 188.        , 180.        ]],

    [[197.        , 199.        , 188.        ],
     [197.        , 199.        , 188.        ],
     [197.        , 199.        , 188.        ],
     ...,
     [189.7552    , 190.7552    , 182.7552    ],
     [187.90625   , 188.90625   , 180.90625   ],
     [187.        , 188.        , 180.        ]],

    ...,

    [[174.13017   , 177.13017   , 166.13017   ],
     [175.43225   , 178.43225   , 167.43225   ],
     [175.22392   , 178.22392   , 167.22392   ],
     ...,
     [185.31621   , 187.31621   , 176.31621   ],
     [189.62546   , 191.62546   , 180.62546   ],
     [190.97185   , 192.97185   , 181.97185   ]],

    [[180.14787   , 183.14787   , 172.14787   ],
     [182.04688   , 185.04688   , 174.04688   ],
     [182.06274   , 185.06274   , 174.06274   ],
     ...,
     [186.26561   , 188.26561   , 177.26561   ],
     [184.54688   , 186.54688   , 175.54688   ],
     [186.69792   , 188.69792   , 177.69792   ]],

    [[188.86389   , 191.86389   , 180.86389   ],
     [187.64581   , 190.64581   , 179.64581   ],
     [187.02422   , 190.02422   , 179.02422   ],
     ...,
     [186.26561   , 188.26561   , 177.26561   ],
     [184.54688   , 186.54688   , 175.54688   ],
     [186.69792   , 188.69792   , 177.69792   ]]],


   [[[172.05588   , 164.05588   ,  39.395832  ],
     [168.01042   , 161.22917   ,  35.822918  ],
     [165.99815   , 160.99815   ,  34.998154  ],
     ...,
     [147.15811   , 134.15811   , 116.78682   ],
     [147.        , 134.        , 118.        ],
     [145.64583   , 132.64583   , 116.645836  ]],

    [[183.60417   , 176.49902   ,  46.0625    ],
     [169.80664   , 163.30371   ,  34.68164   ],
     [165.46875   , 160.46875   ,  31.53125   ],
     ...,
     [158.17352   , 145.17352   , 128.17352   ],
     [157.51465   , 144.19922   , 129.14551   ],
     [156.59473   , 143.59473   , 127.501945  ]],

    [[185.28125   , 178.28125   ,  45.28125   ],
     [179.07292   , 172.07292   ,  39.479168  ],
     [170.08572   , 165.08572   ,  35.088108  ],
     ...,
     [170.55446   , 155.67023   , 131.97916   ],
     [175.5931    , 160.70769   , 139.02019   ],
     [172.25185   , 157.36642   , 135.63358   ]],

    ...,

    [[ 43.13727   ,  73.90809   ,  43.02268   ],
     [ 48.114594  ,  74.88541   ,  43.90689   ],
     [ 48.98036   ,  73.8866    ,  41.62855   ],
     ...,
     [ 99.86578   , 113.86578   ,  80.86578   ],
     [ 98.22919   , 109.22919   ,  76.04169   ],
     [ 99.42711   , 109.42711   ,  75.42711   ]],

    [[ 44.        ,  80.0625    ,  48.59375   ],
     [ 46.96289   ,  78.59375   ,  47.40332   ],
     [ 44.9847    ,  75.05697   ,  43.5       ],
     ...,
     [ 96.05697   , 108.46322   ,  73.99447   ],
     [ 97.99707   , 109.56836   ,  75.37793   ],
     [ 99.50098   , 110.50098   ,  76.50098   ]],

    [[ 42.052094  ,  81.731995  ,  50.392044  ],
     [ 43.61264   ,  78.82292   ,  47.90528   ],
     [ 50.34374   ,  84.34374   ,  51.34374   ],
     ...,
     [103.147705  , 113.147705  ,  79.147705  ],
     [104.33431   , 114.33431   ,  80.33431   ],
     [105.        , 115.        ,  81.        ]]],


   [[[ 13.        ,   0.        ,   0.        ],
     [ 14.78125   ,   7.125     ,   1.78125   ],
     [ 15.817708  ,  16.177082  ,  12.630207  ],
     ...,
     [  5.0937347 ,   6.0937347 ,  10.276024  ],
     [ 10.328125  ,  11.109375  ,  16.4375    ],
     [ 13.        ,  12.        ,  20.        ]],

    [[ 12.21875   ,   0.390625  ,   0.        ],
     [ 12.608398  ,   5.4282227 ,   2.1291504 ],
     [ 12.196289  ,  13.585123  ,  12.701415  ],
     ...,
     [ 13.044601  ,  14.044601  ,  17.516846  ],
     [ 11.890625  ,  12.671875  ,  17.56665   ],
     [ 14.5625    ,  13.5625    ,  20.78125   ]],

    [[ 11.03125   ,   0.984375  ,   0.        ],
     [  9.305664  ,   2.849121  ,   2.657959  ],
     [  6.6917315 ,   9.645344  ,  12.80965   ],
     ...,
     [ 25.129917  ,  26.129917  ,  28.522898  ],
     [ 14.265625  ,  15.046875  ,  19.282959  ],
     [ 16.9375    ,  15.9375    ,  21.96875   ]],

    ...,

    [[ 78.984375  ,  28.015625  ,  23.96875   ],
     [ 73.710205  ,  24.522705  ,  17.803955  ],
     [ 71.41431   ,  26.546875  ,  16.178059  ],
     ...,
     [ 53.700283  ,  31.090902  ,  24.500008  ],
     [ 50.692627  ,  30.536377  ,  21.289795  ],
     [ 46.28125   ,  26.125     ,  15.125     ]],

    [[ 78.390625  ,  28.609375  ,  22.78125   ],
     [ 75.7605    ,  27.760498  ,  19.260498  ],
     [ 73.303795  ,  30.109375  ,  16.017252  ],
     ...,
     [ 63.09205   ,  34.545166  ,  26.281258  ],
     [ 59.7937    ,  33.69995   ,  23.395752  ],
     [ 56.96875   ,  30.875     ,  19.875     ]],

    [[ 78.        ,  29.        ,  22.        ],
     [ 77.109375  ,  29.890625  ,  20.21875   ],
     [ 74.546875  ,  32.453125  ,  15.911459  ],
     ...,
     [ 69.27084   ,  36.81771   ,  27.453133  ],
     [ 65.78125   ,  35.78125   ,  24.78125   ],
     [ 64.        ,  34.        ,  23.        ]]]], 
 dtype=float32)>, <tf.Tensor: shape=(64, 96, 96, 3), 
 dtype=float32, numpy=
array([[[[5.00000000e 00, 4.00000000e 00, 2.00000000e 00],
     [5.00000000e 00, 4.00000000e 00, 2.00000000e 00],
     [5.81250000e 00, 4.81250000e 00, 2.81250000e 00],
     ...,
     [2.81250000e 00, 8.12500000e-01, 1.81250000e 00],
     [2.00000000e 00, 0.00000000e 00, 1.00000000e 00],
     [2.00000000e 00, 0.00000000e 00, 1.00000000e 00]],

    [[9.75000000e 00, 8.75000000e 00, 6.75000000e 00],
     [9.75000000e 00, 8.75000000e 00, 6.75000000e 00],
     [1.29746094e 01, 1.19746094e 01, 9.97460938e 00],
     ...,
     [9.42724609e 00, 7.42724609e 00, 8.42724609e 00],
     [1.09062500e 01, 8.90625000e 00, 9.90625000e 00],
     [1.09062500e 01, 8.90625000e 00, 9.90625000e 00]],

    [[1.94583359e 01, 1.81354179e 01, 1.71041679e 01],
     [1.94583359e 01, 1.81354179e 01, 1.71041679e 01],
     [2.34806328e 01, 2.21577168e 01, 2.11264668e 01],
     ...,
     [2.17687187e 01, 1.97687187e 01, 2.07687187e 01],
     [2.47500019e 01, 2.27500019e 01, 2.37500019e 01],
     [2.47500019e 01, 2.27500019e 01, 2.37500019e 01]],

    ...,

    [[1.22500122e 02, 1.21500122e 02, 1.19500122e 02],
     [1.22500122e 02, 1.21500122e 02, 1.19500122e 02],
     [1.23723122e 02, 1.22723122e 02, 1.20723122e 02],
     ...,
     [6.47745361e 01, 6.47745361e 01, 6.27745399e 01],
     [6.08749695e 01, 6.08749695e 01, 5.88749695e 01],
     [6.08749695e 01, 6.08749695e 01, 5.88749695e 01]],

    [[1.45312500e 02, 1.44312500e 02, 1.42312500e 02],
     [1.45312500e 02, 1.44312500e 02, 1.42312500e 02],
     [1.47692871e 02, 1.46692871e 02, 1.44692871e 02],
     ...,
     [9.76440430e 01, 9.76440430e 01, 9.56440430e 01],
     [9.60000000e 01, 9.60000000e 01, 9.40000000e 01],
     [9.60000000e 01, 9.60000000e 01, 9.40000000e 01]],

    [[1.56000000e 02, 1.55000000e 02, 1.53000000e 02],
     [1.56000000e 02, 1.55000000e 02, 1.53000000e 02],
     [1.56812500e 02, 1.55812500e 02, 1.53812500e 02],
     ...,
     [1.52593750e 02, 1.52593750e 02, 1.50593750e 02],
     [1.53000000e 02, 1.53000000e 02, 1.51000000e 02],
     [1.53000000e 02, 1.53000000e 02, 1.51000000e 02]]],


   [[[1.35819336e 02, 1.73053711e 02, 1.69329758e 02],
     [1.53781250e 02, 1.85254883e 02, 1.82736816e 02],
     [1.44442871e 02, 1.77336426e 02, 1.78929031e 02],
     ...,
     [1.76788788e 02, 2.17132538e 02, 2.43813675e 02],
     [1.74809082e 02, 2.15152832e 02, 2.43215332e 02],
     [1.65743149e 02, 2.06909836e 02, 2.34702301e 02]],

    [[1.06315598e 02, 1.49159348e 02, 1.32346848e 02],
     [1.07478027e 02, 1.48297852e 02, 1.32557129e 02],
     [1.14144371e 02, 1.57785172e 02, 1.45116531e 02],
     ...,
     [2.12427185e 02, 2.49489685e 02, 2.54968750e 02],
     [2.10868652e 02, 2.47931152e 02, 2.54992676e 02],
     [2.10817719e 02, 2.47880219e 02, 2.54768387e 02]],

    [[1.87158203e 01, 8.06440430e 01, 5.01336250e 01],
     [2.25864258e 01, 8.75239258e 01, 5.28364258e 01],
     [4.75966873e 01, 1.14003914e 02, 8.01753006e 01],
     ...,
     [2.14306320e 02, 2.43801132e 02, 2.46281250e 02],
     [2.18003418e 02, 2.46909668e 02, 2.48812500e 02],
     [2.17134277e 02, 2.45803223e 02, 2.49093750e 02]],

    ...,

    [[1.65592941e 02, 1.96327316e 02, 1.69833664e 02],
     [1.74614746e 02, 2.07114746e 02, 1.79302246e 02],
     [1.53045563e 02, 1.93571106e 02, 1.60940903e 02],
     ...,
     [0.00000000e 00, 3.94683151e 01, 4.11930084e-02],
     [1.22426758e 01, 7.24301758e 01, 2.62739258e 01],
     [3.40232964e 01, 9.13993988e 01, 4.44983673e 01]],

    [[0.00000000e 00, 1.18253584e 01, 0.00000000e 00],
     [6.79589844e 00, 1.87114258e 01, 5.32910156e 00],
     [2.10047340e 01, 4.22791557e 01, 2.19179840e 01],
     ...,
     [2.26249371e 01, 9.69895630e 01, 4.79841881e 01],
     [3.05439453e 01, 1.10661621e 02, 5.76782227e 01],
     [4.26578827e 01, 1.11423477e 02, 5.78717308e 01]],

    [[0.00000000e 00, 9.65625000e 00, 1.65625000e 00],
     [1.31250000e 00, 8.31250000e 00, 6.56250000e-01],
     [0.00000000e 00, 1.73958397e 01, 0.00000000e 00],
     ...,
     [5.79341049e 01, 1.45384323e 02, 9.56216049e 01],
     [8.28759766e 01, 1.69545410e 02, 1.16208984e 02],
     [1.05831863e 02, 1.71983673e 02, 1.21395149e 02]]],


   [[[5.48266068e 01, 5.08266068e 01, 2.46495228e 01],
     [5.50257149e 01, 5.09007149e 01, 2.47861328e 01],
     [5.54114571e 01, 4.94114571e 01, 2.41486549e 01],
     ...,
     [5.48154640e 01, 5.06071205e 01, 3.90486298e 01],
     [2.87747402e 01, 2.53264980e 01, 1.54042969e 01],
     [2.67753925e 01, 2.41697044e 01, 1.39439020e 01]],

    [[5.42037773e 01, 5.22037773e 01, 2.96725254e 01],
     [5.28134766e 01, 5.06259766e 01, 2.81279297e 01],
     [5.36598320e 01, 4.87395821e 01, 2.65003262e 01],
     ...,
     [6.91130219e 01, 6.54847565e 01, 4.91549835e 01],
     [4.29394531e 01, 3.85332031e 01, 2.54082031e 01],
     [2.67773819e 01, 2.29971066e 01, 1.02890978e 01]],

    [[5.70909309e 01, 5.50909309e 01, 3.40885429e 01],
     [5.32864571e 01, 5.11025391e 01, 2.99218750e 01],
     [5.34947891e 01, 4.86502800e 01, 2.61718750e 01],
     ...,
     [9.29087906e 01, 8.87532959e 01, 6.31134071e 01],
     [6.43567657e 01, 5.94693985e 01, 3.88740234e 01],
     [3.28602104e 01, 2.78614044e 01, 8.66630650e 00]],

    ...,

    [[8.08130875e 01, 6.68130875e 01, 5.58390427e 00],
     [8.23523483e 01, 6.82309265e 01, 6.93566322e 00],
     [7.84802856e 01, 6.25375786e 01, 1.24501038e 00],
     ...,
     [1.17640701e 02, 1.07686066e 02, 3.86102180e 01],
     [1.22071564e 02, 1.12958923e 02, 4.79309502e 01],
     [1.28132507e 02, 1.18152161e 02, 5.71857948e 01]],

    [[1.14656898e 02, 1.02953773e 02, 2.72350273e 01],
     [1.15920898e 02, 1.04107422e 02, 2.83740234e 01],
     [1.13113281e 02, 9.96445312e 01, 2.37158203e 01],
     ...,
     [1.53180634e 02, 1.47083618e 02, 5.86301727e 01],
     [1.58908203e 02, 1.52472656e 02, 6.93935547e 01],
     [1.51753281e 02, 1.45055038e 02, 6.45241013e 01]],

    [[1.78467621e 02, 1.69653259e 02, 7.47507935e 01],
     [1.78290375e 02, 1.69790680e 02, 7.39831467e 01],
     [1.76013794e 02, 1.66190857e 02, 6.89797974e 01],
     ...,
     [1.67686234e 02, 1.65066422e 02, 5.65305099e 01],
     [1.67636383e 02, 1.65390915e 02, 6.15788460e 01],
     [1.64538742e 02, 1.61901443e 02, 6.07888184e 01]]],


   ...,


   [[[1.17546875e 02, 1.02395836e 02, 7.93958359e 01],
     [1.15453125e 02, 9.67343750e 01, 7.46406250e 01],
     [1.12223961e 02, 8.79583282e 01, 6.77135391e 01],
     ...,
     [8.84687805e 01, 7.10000000e 01, 4.86927643e 01],
     [9.30000000e 01, 7.10000000e 01, 5.75468750e 01],
     [9.30000000e 01, 6.84531174e 01, 6.05468826e 01]],

    [[1.11274094e 02, 9.60262833e 01, 7.44042969e 01],
     [1.14111816e 02, 9.47524414e 01, 7.45805664e 01],
     [1.13518555e 02, 8.90961075e 01, 6.93217773e 01],
     ...,
     [1.01921906e 02, 8.36423416e 01, 6.13484421e 01],
     [1.07153809e 02, 8.54440918e 01, 7.07697754e 01],
     [1.07190506e 02, 8.31874924e 01, 7.24651718e 01]],

    [[1.11863800e 02, 9.73638000e 01, 7.72563477e 01],
     [1.14675293e 02, 9.57586288e 01, 7.70659180e 01],
     [1.14547661e 02, 9.08393326e 01, 7.20328217e 01],
     ...,
     [1.10582077e 02, 9.21505585e 01, 6.88656998e 01],
     [1.15131348e 02, 9.38037949e 01, 7.66209335e 01],
     [1.16233017e 02, 9.29361420e 01, 7.89693222e 01]],

    ...,

    [[3.34529076e 01, 1.27744722e 01, 0.00000000e 00],
     [1.00004509e 02, 6.81486435e 01, 2.02915249e 01],
     [1.59042236e 02, 1.13147179e 02, 3.63206062e 01],
     ...,
     [1.95015884e 02, 1.39584366e 02, 1.22070408e 01],
     [1.90469879e 02, 1.32253387e 02, 1.25335159e 01],
     [1.83808060e 02, 1.25580246e 02, 1.97625771e 01]],

    [[3.33319511e 01, 1.35767422e 01, 0.00000000e 00],
     [1.08526611e 02, 7.80554199e 01, 2.51909180e 01],
     [1.80072845e 02, 1.35266113e 02, 4.96700821e 01],
     ...,
     [1.85928131e 02, 1.29474991e 02, 8.25048065e 00],
     [1.79291992e 02, 1.19676025e 02, 6.69653320e 00],
     [1.69351471e 02, 1.09841049e 02, 1.23887711e 01]],

    [[3.36822929e 01, 1.39270840e 01, 0.00000000e 00],
     [1.13921875e 02, 8.40312500e 01, 2.80937500e 01],
     [1.97880219e 02, 1.54838547e 02, 5.89791641e 01],
     ...,
     [1.77796829e 02, 1.20062439e 02, 6.04162598e 00],
     [1.64437500e 02, 1.03890625e 02, 0.00000000e 00],
     [1.46265594e 02, 8.61145477e 01, 0.00000000e 00]]],


   [[[1.05939857e 02, 7.22836075e 01, 5.32836113e 01],
     [1.07194580e 02, 7.39687500e 01, 5.38977051e 01],
     [1.07669106e 02, 7.45260391e 01, 5.18996582e 01],
     ...,
     [1.22373611e 02, 8.03892365e 01, 7.67173615e 01],
     [1.18265625e 02, 7.36093750e 01, 7.29375000e 01],
     [1.16455963e 02, 6.99687195e 01, 7.16562500e 01]],

    [[1.08517090e 02, 6.81979141e 01, 4.99720879e 01],
     [1.06988770e 02, 6.89943848e 01, 4.87331543e 01],
     [1.08728104e 02, 7.07281036e 01, 4.77572403e 01],
     ...,
     [1.22051018e 02, 7.42978287e 01, 7.22155609e 01],
     [1.21400635e 02, 7.20568848e 01, 7.50268555e 01],
     [1.23591896e 02, 7.35952377e 01, 7.65952377e 01]],

    [[1.17069092e 02, 7.01458359e 01, 5.41458321e 01],
     [1.14718750e 02, 6.91291504e 01, 5.12072754e 01],
     [1.12810791e 02, 6.87083359e 01, 4.95052071e 01],
     ...,
     [1.28756989e 02, 7.81597366e 01, 7.71597366e 01],
     [1.27769775e 02, 7.34604492e 01, 7.62302246e 01],
     [1.30496201e 02, 7.54962006e 01, 8.00691376e 01]],

    ...,

    [[1.39930908e 02, 8.13684082e 01, 9.22902832e 01],
     [1.34566650e 02, 7.49531250e 01, 8.62854004e 01],
     [1.28079834e 02, 6.75815430e 01, 7.92360840e 01],
     ...,
     [1.24175446e 02, 8.33073654e 01, 9.20643539e 01],
     [1.25202148e 02, 8.41281738e 01, 9.38698730e 01],
     [1.24568748e 02, 8.34423599e 01, 9.34347229e 01]],

    [[1.23842285e 02, 8.04531250e 01, 8.70416641e 01],
     [1.24983154e 02, 7.87644043e 01, 8.57019043e 01],
     [1.26321777e 02, 7.91134415e 01, 8.53321915e 01],
     ...,
     [1.30121902e 02, 1.18215645e 02, 1.22215645e 02],
     [1.30850586e 02, 1.18944336e 02, 1.22944336e 02],
     [1.36539169e 02, 1.24632927e 02, 1.28632919e 02]],

    [[1.53647705e 02, 1.28350830e 02, 1.37694580e 02],
     [1.53113525e 02, 1.27606445e 02, 1.36950195e 02],
     [1.59272629e 02, 1.33466721e 02, 1.42878174e 02],
     ...,
     [1.32164215e 02, 1.36432617e 02, 1.37134354e 02],
     [1.31789795e 02, 1.35288330e 02, 1.36375000e 02],
     [1.34850952e 02, 1.38153503e 02, 1.39338165e 02]]],


   [[[1.90000000e 01, 1.50000000e 01, 1.60000000e 01],
     [1.90000000e 01, 1.50000000e 01, 1.60000000e 01],
     [1.92968750e 01, 1.54947920e 01, 1.64947910e 01],
     ...,
     [2.25937538e 01, 1.67916718e 01, 1.86927128e 01],
     [2.20000000e 01, 1.60000000e 01, 1.80000000e 01],
     [2.20000000e 01, 1.60000000e 01, 1.80000000e 01]],

    [[2.05000000e 01, 1.75000000e 01, 1.85000000e 01],
     [2.05000000e 01, 1.75000000e 01, 1.85000000e 01],
     [2.03515625e 01, 1.75494785e 01, 1.85000000e 01],
     ...,
     [2.34947948e 01, 1.76927128e 01, 1.95937538e 01],
     [2.30000000e 01, 1.70000000e 01, 1.90000000e 01],
     [2.30000000e 01, 1.70000000e 01, 1.90000000e 01]],

    [[2.10000000e 01, 2.00000000e 01, 2.06666660e 01],
     [2.10000000e 01, 2.00000000e 01, 2.06666660e 01],
     [2.05546875e 01, 1.96866322e 01, 2.02708340e 01],
     ...,
     [2.43298626e 01, 1.84947948e 01, 2.04453144e 01],
     [2.40000000e 01, 1.80000000e 01, 2.00000000e 01],
     [2.40000000e 01, 1.80000000e 01, 2.00000000e 01]],

    ...,

    [[1.69000031e 02, 1.74000031e 02, 1.67166687e 02],
     [1.69000031e 02, 1.74000031e 02, 1.67166687e 02],
     [1.71144135e 02, 1.76144135e 02, 1.69310791e 02],
     ...,
     [1.35512199e 01, 2.40989590e 01, 2.23020897e 01],
     [1.36666718e 01, 2.40000000e 01, 2.25000076e 01],
     [1.36666718e 01, 2.40000000e 01, 2.25000076e 01]],

    [[1.76500000e 02, 1.81500000e 02, 1.74500000e 02],
     [1.76500000e 02, 1.81500000e 02, 1.74500000e 02],
     [1.78677094e 02, 1.83677094e 02, 1.76677094e 02],
     ...,
     [1.52031231e 01, 2.48515625e 01, 2.37031231e 01],
     [1.55000000e 01, 2.50000000e 01, 2.40000000e 01],
     [1.55000000e 01, 2.50000000e 01, 2.40000000e 01]],

    [[1.82000000e 02, 1.87000000e 02, 1.80000000e 02],
     [1.82000000e 02, 1.87000000e 02, 1.80000000e 02],
     [1.84078125e 02, 1.89078125e 02, 1.82078125e 02],
     ...,
     [1.65052052e 01, 2.56041641e 01, 2.46041641e 01],
     [1.70000000e 01, 2.60000000e 01, 2.50000000e 01],
     [1.70000000e 01, 2.60000000e 01, 2.50000000e 01]]]],
  dtype=float32)>)

CodePudding user response:

Maybe set the shuffle parameter of tf.keras.preprocessing.image_dataset_from_directory to False for train_dataset_target and train_dataset_images and call shuffle after zipping:

train_dataset = tf.data.Dataset.zip((train_dataset_target, train_dataset_target)).shuffle(some_buffer_size)
  • Related