yiranran / APDrawingGAN2

Code for Line Drawings for Face Portraits from Photos using Global and Local Structure based GANs (TPAMI)
223 stars 38 forks source link

TypeError: only integer tensors of a single element can be converted to an index #2

Closed KhaledSharif closed 2 years ago

KhaledSharif commented 4 years ago

Error output

Traceback (most recent call last):
  File "test.py", line 33, in <module>
    for i, data in enumerate(dataset):
  File "/home/khaled/Repositories/APDrawingGAN2/data/__init__.py", line 72, in __iter__
    for i, data in enumerate(self.dataloader):
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "/usr/local/lib/python3.8/dist-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/khaled/Repositories/APDrawingGAN2/data/single_dataset.py", line 98, in __getitem__
    item[regions[i]+'_A'] = A[:,center[i,1]-rhs[i]/2:center[i,1]+rhs[i]/2,center[i,0]-rws[i]/2:center[i,0]+rws[i]/2]
TypeError: only integer tensors of a single element can be converted to an index

How to reproduce

python3 test.py --dataroot dataset/test_single --name apdrawinggan++_author --model test --use_resnet --netG resnet_9blocks --which_epoch 150 --how_many 1000 --gpu_ids 0 --gpu_ids_p 0 --imagefolder images-single

Environment

$ pip3 list | grep torch

torch                   1.4.0        
torchfile               0.1.0        
torchvision             0.5.0

$ uname -a
Linux khaled 5.4.0-31-generic #35-Ubuntu SMP Thu May 7 20:20:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:    20.04
Codename:   focal

$ python3 --version
Python 3.8.2
kavinbj commented 4 years ago

same Error output with same srcipts

my soft environment : torch 1.4.0
torchfile 0.1.0
torchvision 0.5.0 hardware: macbookPro

Traceback (most recent call last): File "test.py", line 33, in for i, data in enumerate(dataset): File "/home/khaled/Repositories/APDrawingGAN2/data/init.py", line 72, in iter for i, data in enumerate(self.dataloader): File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 345, in next data = self._next_data() File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 856, in _next_data return self._process_data(data) File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 881, in _process_data data.reraise() File "/usr/local/lib/python3.8/dist-packages/torch/_utils.py", line 394, in reraise raise self.exc_type(msg) TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop data = fetcher.fetch(index) File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/khaled/Repositories/APDrawingGAN2/data/single_dataset.py", line 98, in getitem item[regions[i]+'_A'] = A[:,center[i,1]-rhs[i]/2:center[i,1]+rhs[i]/2,center[i,0]-rws[i]/2:center[i,0]+rws[i]/2] TypeError: only integer tensors of a single element can be converted to an index

luoww1992 commented 4 years ago

具有相同规则的相同错误输出

我的软环境: 火炬1.4.0 torchfile 0.1.0 torchvision 0.5.0 硬件: macbookPro

追溯(最近一次通话最近): 文件“ test.py”,第33行, 用于i,枚举(数据集)中的数据: 文件“ / home / khaled / Repositories / APDrawingGAN2 / data / init .py”,第72行,在ITER 对于i,在枚举数据(self.dataloader): 文件“/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py”,线路345,在下一个 数据=自._next_data() 文件“ /usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py”,行856,在_next_data 返回自身。_process_data(data) 文件“ / usr / local /lib/python3.8/dist-packages/torch/utils/data/dataloader.py“,第881行,位于_process_data data.reraise() 重新 升高文件“ /usr/local/lib/python3.8/dist-packages/torch/_utils.py”,行394提高self.exc_type(msg) TypeError:在DataLoader工作进程0中捕获到TypeError。 原始回溯(大部分最近一次通话结束): 文件“ /usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/worker.py”,行178,在_worker_loop中, 数据= fetcher.fetch(index), 文件“ /usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py​​“,第44行,在fetch data = [self.dataset [idx]中,可能是_batched_index中的idx 文件] usr / local / lib / python3.8 / dist-packages / torch / utils / data / _utils / fetch.py​​“,第44行, 数据= [self.dataset [idx],可能为_batched_index中的idx] 文件“ /home/khaled/Repositories/APDrawingGAN2/data/singledataset.py”,第98行,位于getitem item [regions [i] +' A'] = A [:,center [i,1] -rhs [i] / 2:center [i,1] + rhs [i] / 2,center [i,0] -rws [i] / 2:center [i,0] + rws [i] / 2] TypeError:仅整数张量单个元素的可以转换为索引

have you solved it, i have the same question

JohnParkerLee commented 4 years ago

Trying to downgrade pytorch.

chinacharlie commented 3 years ago

have you solved it, i have the same question。

KhaledSharif commented 3 years ago

@chinacharlie I haven't, sorry

Amaya-aisi commented 3 years ago

trycenter[i,1].item(), i guess the reason is that center[i,1] is not int type

qinghew commented 3 years ago

check this https://github.com/yiranran/APDrawingGAN/commit/bc10583a244620325c6e4874566112ebbf5d2c7d

qinghew commented 3 years ago

And i use the environment totally same with the requirement of this repository. and it can run successfully.

qinghew commented 3 years ago

if you meets more bugs later, just use int() to transform float index to int

winfried-ripken commented 3 years ago

I have converted the tensors to ints as stated here wherever necessary if it saves anyone a bit of time: https://github.com/winfried-loetzsch/APDrawingGAN2

yiranran commented 2 years ago

Thanks for the replies! The code was run in python2, when run in python3 leads to this error. Here is a commit in another repository to solve this error: https://github.com/yiranran/APDrawingGAN/commit/bc10583a244620325c6e4874566112ebbf5d2c7d