Tutorials icon indicating copy to clipboard operation
Tutorials copied to clipboard

Tuple indexed dataframe

Open luistelmocosta opened this issue 5 years ago • 1 comments

Hey, Olga! First, I would love to thank you for your amazing work. The article is so well written and explained and your code looks super clean. I have been trying to apply your work to a project I am working on but I am having some issues and I am not being able to adapt what you did.

I am trying to apply AL to my test_dataset only, so in the query_the_oracle function my unlabeled_idx are all the indices of the test_dataset. However, my index is a tuple (it refers to the coordinates of a huge image) . So, I adapted the code to something like this:

unlabeled_idx = dataset.ids[0:200]
idx_x = []
idx_y = []
for idx in dataset.ids[0:1000]:
    idx_x.append(idx[0])
    idx_y.append(idx[1])

idx_xmax = max(idx_x)
idx_ymax = max(idx_y)
#print(unlabeled_idx)
num_workers = 4
# Select a pool of samples to query from
if pool_size > 0:    
    pool_idx_x = random.sample(range(1, idx_xmax), pool_size)
    pool_idx_y = random.sample(range(1, idx_ymax), pool_size)
    pool_idx =list(zip(pool_idx_x,pool_idx_y))
    
    pool_loader = DataLoader(dataset, batch_size=batch_size, num_workers=num_workers,
                                          #sampler=SubsetRandomSampler(unlabeled_idx[pool_idx]))
                                          sampler=SubsetRandomSampler(pool_idx))
else:
    pool_loader = DataLoader(dataset, batch_size=batch_size, num_workers=num_workers,
                                          sampler=SubsetRandomSampler(unlabeled_idx)) 

However, when I try to run, I get the following error in the margin_query function: TypeError: list indices must be integers or slices, not tuple

Do you have any idea how can I fix this?

luistelmocosta avatar May 08 '20 15:05 luistelmocosta

Hi Luis, thanks for the kind words ;) I think the easiest way to fix it would be to flatten the indices from 2D to 1D. I am assuming you wanted to keep them in 2D because you might want to see which parts of that huge original image AL is picking out or something like that, but for that you could just define another function that would convert a flattened integer index back to a tuple. Does that help?

opetrova avatar May 08 '20 17:05 opetrova