Practical-Deep-Learning-Book icon indicating copy to clipboard operation
Practical-Deep-Learning-Book copied to clipboard

chapter-4/2-similarity-search-level-1.ipynb Broken float division

Open gitgithan opened this issue 1 year ago • 4 comments

def plot_images(filenames, distances):
    images = []
    for filename in filenames:
        images.append(mpimg.imread(filename))
    plt.figure(figsize=(20, 10))
    columns = 4
    for i, image in enumerate(images):
        ax = plt.subplot(len(images) / columns + 1, columns, i + 1)

ax = plt.subplot(len(images) / columns + 1, columns, i + 1) should be ax = plt.subplot(len(images) // columns + 1, columns, i + 1), subplot requires integers for specifying number of rows/cols

gitgithan avatar Feb 19 '23 06:02 gitgithan

Good catch! Can you send this as a PR?

sidgan avatar Mar 20 '23 19:03 sidgan

i have this error here:

IndexError                                Traceback (most recent call last)
Cell In[47], line 4
      1 for i in range(6):
      2     random_image_index = random.randint(0, num_images)
      3     distances, indices = neighbors.kneighbors(
----> 4         [feature_list[random_image_index]])
      5     # Don't take the first closest image as it will be the same image
      6     similar_image_paths = [filenames[random_image_index]] + \
      7         [filenames[indices[0][i]] for i in range(1, 4)]

IndexError: index 7999 is out of bounds for axis 0 with size 2176

how to fix ?

zoldaten avatar Apr 03 '23 13:04 zoldaten

@zoldaten You may have been affected by https://github.com/PracticalDL/Practical-Deep-Learning-Book/issues/164. I am waiting for the authors to provide feedback on my first PR before going further. It is difficult for readers to make edits for reasons like hardware limitations and jupyter cell output management.

gitgithan avatar Apr 03 '23 14:04 gitgithan

@gitgithan ok. hm, it starts working... may be that was mix of pickle saves. i`ve tested stages of saves: 1.

pickle.dump(standard_feature_list, open('features-caltech101-resnet.pickle', 'wb'))
pickle.dump(filenames, open('filenames-caltech101.pickle','wb'))
pickle.dump(generator.classes, open('class_ids-caltech101.pickle',
                                    'wb'))
pickle.dump(filenames, open('filenames-caltech101.pickle', 'wb'))
pickle.dump(
    feature_list,
    open('features-caltech101-' + model_architecture + '.pickle', 'wb'))
pickle.dump(
    feature_list,
    open('features-caltech101-resnet-finetuned.pickle', 'wb'))

and moved saves every time not let them replace each other. hm, works.

here`s my notebooks with depredations fixed: notebooks.zip

zoldaten avatar Apr 03 '23 17:04 zoldaten