sethuiyer / Image-to-Image-Search

A reverse image search engine powered by elastic search and tensorflow
MIT License
320 stars 50 forks source link

After uploading a image i am getting following error #3

Closed anshul12112 closed 5 years ago

anshul12112 commented 5 years ago

F = np.row_stack(x['image']['feat'] for x in batch) GET http://localhost:9200/desearch/_search [status:404 request:0.118s] [2019-04-11 00:45:39,134] ERROR in app: Exception on / [POST] Traceback (most recent call last): File "/home/anshul/.local/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/home/anshul/.local/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/anshul/.local/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/anshul/.local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise raise value File "/home/anshul/.local/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/home/anshul/.local/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functionsrule.endpoint File "server.py", line 61, in index answers = description_search(query) File "server.py", line 31, in description_search "match": {"description": query} File "/home/anshul/.local/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 76, in _wrapped return func(*args, params=params, **kwargs) File "/home/anshul/.local/lib/python3.6/site-packages/elasticsearch/client/init.py", line 660, in search doc_type, '_search'), params=params, body=body) File "/home/anshul/.local/lib/python3.6/site-packages/elasticsearch/transport.py", line 318, in perform_request status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout) File "/home/anshul/.local/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 186, in perform_request self._raise_error(response.status, raw_data) File "/home/anshul/.local/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.NotFoundError: NotFoundError(404, 'index_not_found_exception', 'no such index') 127.0.0.1 - - [11/Apr/2019 00:45:39] "POST / HTTP/1.1" 500 -

anshul12112 commented 5 years ago

help me in resolving this issue

sethuiyer commented 5 years ago

Can you explain your issue in detail? From what it looks like, the index has not been properly set up in the elastic search service. Did you run index.py before launching server.py?

Ideally these steps should have been followed.

  1. Launch Elastic search service in localhost:9200
  2. Run index.py which parses dataset.json to index them in the elastic search service.
  3. Run server.py to launch the webapp.

This video covers the steps to execute before launching the webapp.

anshul12112 commented 5 years ago

sir, Thank you so much for replying i really need your help while running index.py . i got following error anshul@anshul-superuser:~/Image-to-Image-search$ python3.6 index.py Traceback (most recent call last): File "index.py", line 8, in data = json.load(f) File "/usr/lib/python3.6/json/init.py", line 299, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "/usr/lib/python3.6/json/init.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

i am very grateful to you if you resolve this issue

sethuiyer commented 5 years ago

I am glad to be of a help!. It looks like dataset.json/ custom_dataset.json is not properly encoded. This is why the index wasn't properly set up and you were getting Error 404 in server.py

anshul12112 commented 5 years ago

I am glad to be of a help!. It looks like dataset.json/ custom_dataset.json is not properly encoded. This is why the index wasn't properly set up and you were getting Error 404 in server.py

i am new to elastic search i do not know exactly what to do. sir can you tell me step by step procedure

sethuiyer commented 5 years ago

Elastic search is the search engine which we are using here. Before we start searching, we should have something to search.

That information is encoded in dataset.json. So your dataset.json should contain the information about the image path and the corresponding description encoded in proper way.

Once the dataset.json is properly encoded, index.py can help elastic search know the same information.

anshul12112 commented 5 years ago

Sir, i already set up elastic search . it is working on localhost:9200. you told that dataset.json is not properly encoded. so what to do with JSON file.how this issue will resolve Screenshot from 2019-04-11 09-30-34

sethuiyer commented 5 years ago

There is no problem with Elastic search service. The problem is with the dataset.json/ custom_dataset.json.

Run this code after substituting the part inside glob.glob with the path to the folder where you have the images which you wish to search against.

import json
import glob

image_database = glob.glob('/static/img/<your_path_here>') #gets all the image path from the desired folder
dataset_list = []
for image in image_database:
    image.show()
    print 'Enter the description':
    description = input()
    img_data = {}
    img_data['imgurl'] = image
    img_data['description'] = description
    dataset_list.append(img_data)
dataset_json = {}
dataset_json['images'] = dataset_list
json.dump(dataset_json, open('custom_dataset.json','wb')

This will create an custom_dataset.json and then you can run custom_index.py. Let me know if this step works.

Meanwhile, I will work on making an webapp where one can upload bunch of images, choose to have custom caption or automatic caption, view the images present in the index etc in my free time. That should make the whole dataset.json not so important to run the application.

anshul12112 commented 5 years ago

Sir, i am very thankful to you. you help me in resolving issue but sir still whole issue is not resolved while running custom_index.py i am getting following error .please sir help me Traceback (most recent call last): File "custom_index.py", line 25, in data = json.load(f) File "/usr/lib/python3.6/json/init.py", line 299, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "/usr/lib/python3.6/json/init.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)