Unable to extract a tar.gz file for image classification

Hello everyone!

I was trying to play around with the food-101 dataset


Untar didn’t work becase something in the source code that I read stopped it from unzipping a tar.gz file.
I downloaded it using wget (and the ! method in Jupyter notebook) and then tried to untar it using the tarfile module in python but that didn’t work either, and I got this error
TypeError: expected str, bytes or os.PathLike object, not TarFile

Any help would be greatly appreciated!

1 Like

Hii @vishak I’m facing the same issue right now, so kindly let me know if you have found a solution for that issue.


@vishak @AjayStark
Can you please share the line of code you wrote to untar the file?

In general, I think the best way to untar a file is to use the command line(or the ! method from jupyter notebook) itself.
Go to the directory where the tar file is present,(in your case, if you downloaded the file with the wget method from the Jupiter notebook, the file should be present in the same directory).

then type

!tar xvzf <filename.tar.gz>

that should work fine.

(as a suggestion, first shift the file into the Config.data_path directory (most probably (~/.fastai/data), and shift it into a directory, and then untar from there, so that if the file contains multiple files/folders, you need not shift each one of them to a convenient location
You can do that from the command line itself)

1 Like

Hi @PalaashAgrawal Thank you for the reply.
In my case, the issue was that the untar_data() by default adds .tar.gz extension to the url so removing the extension worked well.

Well I think what I’ve done is a unnecessarily complicated cuz I just kept hacking at it.
But here’s how I did it. The first few cells deal with that.

1 Like

Ohh, luckily untar worked well for me :slight_smile:

Also that worked on GoogleColab.
How do I access files that I have uploaded in jupyter notebook?