Broken image references when importing notebooks into Kaggle

I do the following:

  1. Open Kaggle project
  2. Import notebook via github

The code runs fine (after some tweaks) but all of the images in the notebook are broken:

image

Here’s the reference:

image

Any ideas? Does Kaggle not automatically import references?

1 Like

Can you post the link to the Kaggle notebook maybe?
It will be easier to debug.

The code you posted tries to load an image from images directory.
I assume you have copied your images over to Kaggle and put them inside an images directory?
I would check if the path is correct…

I did not copy any images over. The only thing I’ve done so far is import the notebook from the fastai/fastbook repository. I’m guessing it does not also copy the images over (I’ve very new to this!).

Is there an easy way to do this? Here is the notebook:

https://www.kaggle.com/code/williamsaxton/fast-ai-part-1-2

PS Google Colab was able to automagically reference the files when I opened up the notebook in it.

This was driving me crazy. I figured out a way to solve the problem, but it’s probably not the correct or best way to do it.

In your notebook that has broken images in Kaggle (e.g. 01_intro.ipynb):

  • File → Upload Data → Upload Dataset → Link → Import GitHub repository → URL: https://github.com/fastai/fastbook/ → dataset title “testdataset” → Create

  • Create a code cell in the notebook, and Copy the files to the working directory, using !cp -r ../input/testdataset/images ./

  • Reload the page

  • (troubleshooting) If for some reason that directory wasn’t found, maybe check to add the newly created dataset manually, but it should have already done that.
    * File → Add Input → [Select Your Work & Datasets] → [Select the [+] icon for the dataset you created]

You should only have to create the dataset once. On future notebooks, such as for lesson 2, you could simply mount your dataset (as in the last step), and run the !cp and refresh the page.

edit: The smarter way to do it is to just clone the repo, haha - not sure where my head was at for the first suggestion

Solution

Run these commands in a code cell, and refresh the page:

!git clone https://github.com/fastai/fastbook
!cp -r ./fastbook/images ./