Answers for "pytorch dataloader to numpy array"

0

pytorch dataloader to numpy array

# index is the specific data your want in dataloader
import numpy as np
def transfer_dataloader(dataloader, index=0):
    cache_list = list(iter(dataloader))
    assert len(cache_list) > 0
    assert index < len(cache_list[0])
    result_list = np.array(list(map(lambda x: x[index].numpy(), cache_list)))
    return result_list
Posted by: Guest on October-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language