1

Why do I receive the following Exception? How can I solve this?

scores = [(dists[id], img_paths[id]) for id in ids]

TypeError: only integer scalar arrays can be converted to a scalar index

    img = Image.open(file.stream)  # PIL image
    uploaded_img_path = "static/uploaded/" + datetime.now().isoformat() + "_" + file.filename
    img.save(uploaded_img_path)

    img = img.resize((224, 224))  # VGG must take a 224x224 img as an input
    query = fe.extract(img)
    dists = np.linalg.norm(features - query.reshape((64,64,-1)), axis=1)  # Do search
    ids = np.argsort(dists)[:30] # Top 30 results

    scores = [(dists[id], img_paths[id]) for id in ids]

    return render_template('index.html',
                           query_path=uploaded_img_path,
                           scores=scores)
else:
    return render_template('index.html')
kalehmann
  • 4,821
  • 6
  • 26
  • 36
  • error :- scores = [(dists[id], img_paths[id]) for id in ids] TypeError: only integer scalar arrays can be converted to a scalar index – anshul dubey Apr 11 '19 at 05:44
  • Your code will not run because it is part of a function. Please provide a [mcve]. – gmds Apr 11 '19 at 06:06

0 Answers0