0

I am attempting to create a list which shuffles 2 lists together. The code that I have written is provided for your reference:

def __init__(self, path, split_ratio, x, y, color_space='rgb'):
    self.x = x
    self.y = y
    self.path = path
    self.color_space = color_space
    self.path_train_images = path + "train/images/"
    self.path_train_labels = path + "train/labels/"
    self.path_test_images = path + "test/images/"
    self.path_test_labels = path + "test/labels/"
    self.image_file_list = get_png_filename_list(self.path_train_images)
    self.label_file_list = get_png_filename_list(self.path_train_labels)
    self.image_file_list[:], self.label_file_list[:] = self.shuffle_image_label_lists_together()

I am getting ValueError which states:

self.image_file_list[:], self.label_file_list[:] = self.shuffle_image_label_lists_together()
ValueError: not enough values to unpack (expected 2, got 0)

function shuffle_image_label_lists_together is suggested below

def shuffle_image_label_lists_together(self):
        combined = list(zip(self.image_file_list, self.label_file_list))
        random.shuffle(combined)
        return zip(*combined)

It seems self.shuffle_image_label_lists_together() is empty and that is the reason for the error. Could you let me know if my syntax is accurate?

DevanDev
  • 161
  • 1
  • 2
  • 17
  • 1
    What does your function `self.shuffle_image_label_lists_together()` return? – Matthias Feb 18 '21 at 16:46
  • Does this answer your question? ['ValueError: not enough values to unpack (expected 2, got 0)'](https://stackoverflow.com/questions/40706847/valueerror-not-enough-values-to-unpack-expected-2-got-0) – Aris Feb 18 '21 at 16:47
  • @Aristotle No, i have checked the post before – DevanDev Feb 18 '21 at 16:50
  • The error says that `shuffle_image_label_lists_together` doesn't return anything, it must return a tuple with two values to code works. – mirhossein Feb 18 '21 at 16:52
  • @Matthias i have edited my file , please review it. – DevanDev Feb 18 '21 at 16:54
  • @mirhossein, the function returns zip file,i have edited the question, please check it. – DevanDev Feb 18 '21 at 18:23
  • It looks like that `get_png_filename_list` makes `self.image_file_list` and `self.label_file_list` empty so `shuffle_image_label_lists_together` couldn't return a tuple with two values – mirhossein Feb 18 '21 at 20:22
  • 1
    Without seeing your `self.shuffle_image_label_lists_together()`, I'm guessing it modifies values in-place and either has no `return` statement or returns `None`. Update: I copy/pasted your code and added in a dummy `get_png_filename_list()` that returned a fixed list of 3 strings, and it worked like a charm, but if I made `get_png_filename_list()` return `[]` instead, it crashed the same way you said yours did. So it seems your `get_png_filename_list()` is returning an empty string for one or both cases. I'd look there for your issue. – Chance Feb 18 '21 at 16:50
  • I have modified my question, please review it. – DevanDev Feb 18 '21 at 18:23

0 Answers0