zhirongw / lemniscate.pytorch

Unsupervised Feature Learning via Non-parametric Instance Discrimination

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'CIFAR10Instance' object has no attribute 'train_labels' and broken pipe error

1170300814 opened this issue · comments

I do not know what is going on about this.my pytorch version is 1.2.0+cu92 torchvision version is 0.4.0+cu92 cuda 10.0
I just copy the code and try to exe it with "run cifar.py --nce-k 0 --nce-t 0.1 --lr 0.03"

ERROR info is below:

_==> Preparing data..
Files already downloaded and verified
Files already downloaded and verified
==> Building model..

Epoch: 0
0.03
Traceback (most recent call last):

File "E:\pythondaima\lemniscate.pytorch\cifar.py", line 164, in
train(epoch)

File "E:\pythondaima\lemniscate.pytorch\cifar.py", line 137, in train
for batch_idx, (inputs, targets, indexes) in enumerate(trainloader):

File "C:\Users\lenovo\AppData\Roaming\Python\Python37\site-packages\torch\utils\data\dataloader.py", line 278, in iter
return _MultiProcessingDataLoaderIter(self)

File "C:\Users\lenovo\AppData\Roaming\Python\Python37\site-packages\torch\utils\data\dataloader.py", line 682, in init
w.start()

File "G:\python3.7\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)

File "G:\python3.7\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)

File "G:\python3.7\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)

File "G:\python3.7\lib\multiprocessing\popen_spawn_win32.py", line 89, in init
reduction.dump(process_obj, to_child)

File "G:\python3.7\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj) #报错 broken pipe

BrokenPipeError: [Errno 32] Broken pipe

Traceback (most recent call last):
File "", line 1, in
File "G:\python3.7\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "G:\python3.7\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "G:\python3.7\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "G:\python3.7\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="mp_main")
File "G:\python3.7\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "G:\python3.7\lib\runpy.py", line 96, in run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "G:\python3.7\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "E:\pythondaima\lemniscate.pytorch\cifar.py", line 182, in
acc = kNN(0, net, lemniscate, trainloader, testloader, 200, args.nce_t, 1)
File "E:\pythondaima\lemniscate.pytorch\try2.py", line 80, in kNN
trainLabels = torch.LongTensor(trainloader.dataset.train_labels).cuda()
AttributeError: 'CIFAR10Instance' object has no attribute 'train_labels

image
HERE "CIFAR10Instance' object has no attribute 'train_labels
"

I know how to deal with broken pipe . I am running in local environment . SO num_workers should be 0.

if this error is not a specific error. i wonder the author how to exe the code.

i know what to do ....
change to
`def getitem(self, index):

    img, target = self.data[index], self.targets[index]

    # doing this so that it is consistent with all other datasets
    # to return a PIL Image
    img = Image.fromarray(img)

    if self.transform is not None:
        img = self.transform(img)

    if self.target_transform is not None:
        target = self.target_transform(target)

    return img, target, index`
commented

In case anyone wonders why,

In recent versions, the variable for the labels for the training samples in torchvision.datasets.CIFAR10 is not called "train_labels" anymore, instead, it is called "targets". Consequently, you have to change the "train_labels" variable for "targets" everywhere in the file /cifar10/dataset/cifar10.py.

'CIFAR10' object has no attribute 'train_labels'

Hi,

You need to change "train_data" and "train_labels" with "data" and "targets" like,

img, target = self.data[index], self.targets[index]