Chapter 9 - p.292 - plot_image_from_batch

Hi,

I’m getting an error when trying to plot an image and its bounding box:

def plot_image_from_batch(X, y, img_idx):
    class_name = labels[y[0][img_idx]]
    bbox = y[1][img_idx]
    plot_image(X[img_idx], [[*bbox, class_name]])
plot_image_from_batch(X, y_class, y_bbox, 0)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-68472681ff85> in <module>
      3     bbox = y[1][img_idx]
      4     plot_image(X[img_idx], [[*bbox, class_name]])
----> 5 plot_image_from_batch(X, y_class, y_bbox, 0)

TypeError: plot_image_from_batch() takes 3 positional arguments but 4 were given

OK, got it. The sample notebook contains the correct code. It’s just not in sync with the book. The correct code is:

def plot_image_from_batch(X, y_class, y_bbox, img_idx):
    class_name = labels[y_class[img_idx]]
    bbox = y_bbox[img_idx]
    plot_image(X[img_idx], [[*bbox, class_name]])
plot_image_from_batch(X, y_class, y_bbox, 1)

Thanks! That looks like a mistake in the book indeed! We’ll fix this in the next update.