willard-yuan / flask-keras-cnn-image-retrieval

🚀CNN-based image retrieval built on Keras
517 stars 175 forks source link

index.py在python3.6下报错TypeError: No conversion path for dtype: dtype('<U28') #13

Closed TerenceCYJ closed 5 years ago

TerenceCYJ commented 6 years ago

报错代码:h5f.create_dataset('dataset_2', data = names) 原因:create_dataset 只接受 ascii 的数据,如果你是Python3或者python使用utf-8的编码就会报错。 解决办法:

h5f.create_dataset('dataset_2', data = names)

namess = [] for j in names: namess.append(j.encode()) h5f.create_dataset('dataset_2', data = namess) h5f.close()

Max-Fu commented 6 years ago

There's an easier way: change h5f.create_dataset('dataset_2', data = names) into h5f.create_dataset('dataset2', data = np.string(names)) after importing numpy.

Regards

willard-yuan commented 6 years ago

@TerenceCYJ @Max-Fu There is a pull request #11 using Python 3.6. I don't know whether it's compatible with Python 2.7. The code in this part is written as follows:

h5f = h5py.File(output, 'w')
h5f.create_dataset('dataset_1', data=feats)
h5f.create_dataset('dataset_2', data=[name.encode("utf-8") for name in names])
h5f.close()

Do you have time to test it whether it's compatible with Python 2.7?

Max-Fu commented 6 years ago

Sorry, I have only tested on Python 3.6 (currently I don't have Python 2.7 on my server).

Regards.

willard-yuan commented 6 years ago

@Max-Fu Thank you for your test. When you test it on Python 3.6, do you have make some changes? or it just have this problem addressed here?

Max-Fu commented 6 years ago

@willard-yuan I have only changed the part addressed above.