Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'float' object cannot be interpreted as an integer #1051

Closed
Ringhu opened this issue Apr 14, 2020 · 6 comments
Closed

TypeError: 'float' object cannot be interpreted as an integer #1051

Ringhu opened this issue Apr 14, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@Ringhu
Copy link

Ringhu commented Apr 14, 2020

Hi @glenn-jocher , I git clone ur latest version today. But when I run train.py like
python train.py --cfg=cfg/yolov3-tiny.cfg --multi-scale --device=1,2,3,5 --weights=
this, I got the error:
`
Traceback (most recent call last):

File "train.py", line 429, in

train()  # train normally

File "train.py", line 235, in train

for i, (imgs, targets, paths, _) in pbar:  # batch -------------------------------------------------------------

File "/home/hulining/.local/lib/python3.6/site-packages/tqdm/_tqdm.py", line 1032, in iter
for obj in iterable:

File "/home/hulining/anaconda3/envs/pt/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 345, in next
data = self._next_data()

File "/home/hulining/anaconda3/envs/pt/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
return self._process_data(data)
File "/home/hulining/anaconda3/envs/pt/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
data.reraise()

File "/home/hulining/anaconda3/envs/pt/lib/python3.6/site-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 "/home/hulining/anaconda3/envs/pt/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)

File "/home/hulining/anaconda3/envs/pt/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/hulining/anaconda3/envs/pt/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]

File "/proj/hulining/home/download/yolov3/utils/datasets.py", line 420, in getitem
img, labels = load_mosaic(self, index)

File "/proj/hulining/home/download/yolov3/utils/datasets.py", line 543, in load_mosaic
img4 = np.full((s * 2, s * 2, img.shape[2]), 114, dtype=np.int8) # base image with 4 tiles

File "/home/hulining/.local/lib/python3.6/site-packages/numpy/core/numeric.py", line 325, in full
a = empty(shape, dtype, order)

TypeError: 'float' object cannot be interpreted as an integer
`
Could u solve it?

@Ringhu Ringhu added the bug Something isn't working label Apr 14, 2020
@glenn-jocher
Copy link
Member

glenn-jocher commented Apr 14, 2020

@Ringhu we recently changed this code to replace 3 with img.shape[2]. You might try undoing the change to see if this solves the problem for you. We have not seen any issues like this.

img4 = np.full((s * 2, s * 2, img.shape[2]), 114, dtype=np.int8) # base image with 4 tiles

@Ringhu
Copy link
Author

Ringhu commented Apr 15, 2020

Thanks for ur reply. I fugure it out. It's because the variable s become a float variable for some reason I don't know. When I change the type of s (which is img_size) to int, the problem solved.

@Ringhu Ringhu closed this as completed Apr 15, 2020
@anisaha1
Copy link

anisaha1 commented May 4, 2020

@glenn-jocher The issue is here.

If imgsz_min equals imgsz_max (let's say I pass [320, 320, 320]) and I also have --multi-scale, then the divisions imgsz_min //= 1.5 and imgsz_max //= 0.667 return floats which throws error in the mosaic function. Probably you have never used this combination of arguments. Casting it to int will solve the problem.

@glenn-jocher
Copy link
Member

@anisaha1 thank you for the clear explanation! We've implemented a fix in d405959. Can you git pull and try again?

@glenn-jocher glenn-jocher reopened this May 4, 2020
@anisaha1
Copy link

anisaha1 commented May 6, 2020

Thanks! It is solved now.

@glenn-jocher
Copy link
Member

@anisaha1 great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants