HCIILAB / SCUT-FBP5500-Database-Release

A diverse benchmark database for multi-paradigm facial beauty prediction
737 stars 146 forks source link

TypeError: slice indices must be integers or None or have an __index__ method #9

Open a-whitej opened 5 years ago

a-whitej commented 5 years ago

Traceback (most recent call last): File "forward.py", line 134, in main() File "forward.py", line 98, in main means = get_mean_npy(mean_file, crop_size = batch_shape[2:], isColor = is_color) File "forward.py", line 20, in get_mean_npy (_shape[3] - crop_size[1]) / 2:(_shape[3] + crop_size[1]) / 2] TypeError: slice indices must be integers or None or have an index method

RojunLin commented 5 years ago

Do you change any argments in "forward.py"? It runs well on my computer.

a-whitej commented 5 years ago

I didnot make any code change. Clone new caffe code with windows version and make install. And run forward.py just it

RojunLin commented 5 years ago

may be the python version differences. You can change the code like this: mean_npy = mean_npy[ :, int((_shape[2] - crop_size[0]) / 2) : int((_shape[2] + crop_size[0]) / 2), int((_shape[3] - crop_size[1]) / 2) : int((_shape[3] + crop_size[1]) / 2)]

a-whitej commented 5 years ago

I did this.

Pytorch version has issue.

Anaconda: 3-4.1.1 torch : 1.1.0

Traceback (most recent call last): File "forward.py", line 86, in main() File "forward.py", line 44, in main load_model(torch.load('./models/alexnet.pth'), net) File "E:\Anaconda34\lib\site-packages\torch\serialization.py", line 387, in load return _load(f, map_location, pickle_module, **pickle_load_args) File "E:\Anaconda34\lib\site-packages\torch\serialization.py", line 574, in _load result = unpickler.load() UnicodeDecodeError: 'ascii' codec can't decode byte 0xa4 in position 2: ordinal not in range(128)

a-whitej commented 5 years ago

For pytorch issue(on Python 3.5.2)

Add:

from functools import partial import pickle pickle.load = partial(pickle.load, encoding="latin1") pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")

And make change:

load pretrained model

load_model(torch.load('./models/alexnet.pth',pickle_module=pickle), net)
ygrayson commented 5 years ago

I encountered this error as well. At some point in the index there is a "divide by 2" and Python would possibly treat it as float number after dividing by 2. Using integer casting int() should solve the problem.

Mine works well in the caffe version. Not fully sure about Pytorch version.