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

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

ValueError: Illegal slicing argument for scalar dataspace #28

Closed dgtlmoon closed 4 years ago

dgtlmoon commented 5 years ago

Indexing worked fine

Using TensorFlow backend.
--------------------------------------------------
         feature extraction starts
--------------------------------------------------
2019-02-18 01:14:32.787757: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
extracting feature from image No. 1 , 9 images in total
extracting feature from image No. 2 , 9 images in total
extracting feature from image No. 3 , 9 images in total
extracting feature from image No. 4 , 9 images in total
extracting feature from image No. 5 , 9 images in total
extracting feature from image No. 6 , 9 images in total
extracting feature from image No. 7 , 9 images in total
extracting feature from image No. 8 , 9 images in total
extracting feature from image No. 9 , 9 images in total
--------------------------------------------------
      writing feature extraction results ...
--------------------------------------------------
dgtlmoon@acer:/tmp/flask-keras-cnn-image-retrieval$ ls -al index.save 
-rw-rw-r-- 1 dgtlmoon dgtlmoon 20741 Feb 18 01:14 index.save

but...

$ python query_online.py -query query/541daeb93a3e4cd8a101b7d5e83a6779.jpg -index ./index.save -result result/
Using TensorFlow backend.
[[0.         0.27786013 0.         ... 0.00188846 0.02606245 0.        ]
 [0.05857334 0.06311509 0.03466835 ... 0.         0.         0.        ]
 [0.02201021 0.         0.05797203 ... 0.01631281 0.06619522 0.01133065]
 ...
 [0.03652793 0.         0.01706417 ... 0.         0.10876585 0.        ]
 [0.01404525 0.         0.01023624 ... 0.         0.01086351 0.03146496]
 [0.03362079 0.00451447 0.         ... 0.         0.05480169 0.01739029]]
Traceback (most recent call last):
  File "query_online.py", line 28, in <module>
    imgNames = h5f['dataset_2'][:]
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/dataset.py", line 463, in __getitem__
    selection = sel2.select_read(fspace, args)
  File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/selections2.py", line 103, in select_read
    return ScalarReadSelection(fspace, args)
  File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/selections2.py", line 88, in __init__
    raise ValueError("Illegal slicing argument for scalar dataspace")
ValueError: Illegal slicing argument for scalar dataspace
dgtlmoon commented 5 years ago

@willard-yuan

diff --git a/index.py b/index.py
index ac3c737..04067c7 100644
--- a/index.py
+++ b/index.py
@@ -59,5 +59,5 @@ if __name__ == "__main__":
     h5f = h5py.File(output, 'w')
     h5f.create_dataset('dataset_1', data = feats)
     # h5f.create_dataset('dataset_2', data = names)
-    h5f.create_dataset('dataset_2', data = np.string_(names))
+    h5f.create_dataset('dataset_2', data = names)
     h5f.close()
diff --git a/query_online.py b/query_online.py
index 50f79f1..9804012 100644
--- a/query_online.py
+++ b/query_online.py
@@ -22,6 +22,7 @@ args = vars(ap.parse_args())

 # read in indexed images' feature vectors and corresponding image names
 h5f = h5py.File(args["index"],'r')
+print (h5f['dataset_2'])
 # feats = h5f['dataset_1'][:]
 feats = h5f['dataset_1'][:]
 print(feats)
@@ -59,7 +60,7 @@ print("top %d images in order are: " %maxres, imlist)

 # show top #maxres retrieved result one by one
 for i,im in enumerate(imlist):
-    image = mpimg.imread(args["result"]+"/"+str(im, 'utf-8'))
+    image = mpimg.imread(args["result"]+"/"+str(im))
     plt.title("search output %d" %(i+1))
     plt.imshow(image)
     plt.show()

sort of helps.. but missing results/foobar.jpeg etc are missing

willard-yuan commented 5 years ago

@dgtlmoon To fix the bug, please try to comment line 62 in index.py, and use line 61 instead.

The problem is caused by h5py library for different version of Python. Thanks for report the bug.