Iām working through An Introduction to Statistical Learning with Applications in Python (ISLP), Chapter 10. I wanted to keep the chapterās data and a ResNet50 checkpoint in a private Kaggle Dataset so I wouldnāt have to download everything again in each Notebook session
The process exposed a few issues that were not obvious from the local ZIP structure
1. The Dataset upload failed because Kaggle unpacked a nested archive
My ZIP contained both:
data/cifar-100-python/
data/cifar-100-python.tar.gz
Kaggle Support checked the failed uploads and confirmed this backend error:
Directory already exists: cifar-100-python
Kaggle unpacks uploaded archives server-side. The existing directory and the directory created by extracting the .tar.gz collided. Kaggle removed the incomplete Dataset after processing failed, which is why it never appeared in my Dataset list. Support also confirmed that my intended Dataset slug was not reserved
The fix was to keep the already-extracted cifar-100-python/{train,test,meta} directory in the Kaggle-specific ZIP and exclude the duplicate tar archive
I also checked eight other .gz files by comparing the SHA256 and byte size of their decompressed contents with existing sibling files. Those pairs were identical, so I omitted the redundant compressed copies from this upload package
The rebuilt ZIP had 29 entries, was 315.35 MiB, used POSIX / paths, and passed the ZIP CRC test
2. Creating a Dataset did not attach it to my existing Notebook
After the Dataset was created, /kaggle/input was still empty in my Notebook because I had not attached the Dataset
I had to use Add Input ā Your Datasets
After attaching it, the actual path in my Notebook was:
/kaggle/input/datasets/<owner>/<dataset-slug>/
I have replaced the owner and slug with placeholders because the Dataset is private. The important point is that the actual mount path included an additional datasets/<owner>/ level. I now enumerate /kaggle/input instead of assuming the path is simply /kaggle/input/<slug>
3. ISLPās IMDB loader expected .tensor.gz, but Kaggle Input is read-only
I had kept the decompressed IMDB files, such as IMDB_X_test.tensor, but omitted the byte-identical .tensor.gz copy
ISLP 0.5.0 still looked for IMDB_X_test.tensor.gz. When it did not find that filename, it tried to download the file and write it under the supplied root directory. Since that directory was under /kaggle/input, it failed with:
OSError: [Errno 30] Read-only file system
The data itself was present; the loader did not automatically treat the uncompressed sibling as an equivalent file
As a temporary Notebook-side workaround, I patched the moduleās _get_imdb() lookup for the current session: when a requested .tensor.gz is absent but the corresponding .tensor exists, return the .tensor path; otherwise call the original function. I restore the original function in a finally block
The following is a minimal version of the workaround. It assumes ISLP==0.5.0 is installed and the Dataset is already attached. Replace <owner> and <dataset-slug> with your actual mount path:
from pathlib import Path
import ISLP.torch.imdb as imdb
IMDB_DIR = Path(
"/kaggle/input/datasets/<owner>/<dataset-slug>/data/IMDB"
)
_original_get_imdb = imdb._get_imdb
def _get_imdb_kaggle(
imdb_file,
outdir,
urlbase="http://imdb.jtaylor.su.domains/jtaylor/data/"
):
requested = Path(outdir) / imdb_file
if requested.name.endswith(".tensor.gz"):
plain = requested.with_suffix("")
if not requested.exists() and plain.is_file():
return str(plain)
return _original_get_imdb(imdb_file, outdir, urlbase)
imdb._get_imdb = _get_imdb_kaggle
try:
imdb_train, imdb_test = imdb.load_tensor(root=str(IMDB_DIR))
seq_train, seq_test = imdb.load_sequential(root=str(IMDB_DIR))
lookup = imdb.load_lookup(root=str(IMDB_DIR))
finally:
imdb._get_imdb = _original_get_imdb
print("Tensor:", len(imdb_train), len(imdb_test))
print("Sequential:", len(seq_train), len(seq_test))
print("Vocabulary entries:", len(lookup))
This modifies an internal helper only for the current Python process. It is a practical workaround, not a documented public ISLP API. A kernel restart removes the patch, so the cell must be rerun before loading IMDB again. It does not modify the Dataset
What I verified
My Kaggle runtime was Python 3.13, PyTorch 2.11.0+cpu, torchvision 0.26.0+cpu, and ISLP 0.5.0
- MNIST: 60,000 train / 10,000 test, loaded with
download=False
- CIFAR-100: 50,000 train / 10,000 test, loaded with
download=False
- IMDB Tensor and Sequential: 25,000 train / 25,000 test each;
load_lookup() returned 88,587 entries
- ResNet50: local checkpoint SHA256 matched its filename prefix;
load_state_dict(strict=True) matched all keys; a CPU forward pass on a zero tensor returned shape (1, 1000)
I have not run the full Chapter 10 Notebook or training, and the ResNet50 test was only a dummy-input forward pass, not real-image classification
Questions
- Is there a cleaner supported way to point ISLP 0.5.0ās IMDB loader at already-decompressed local
.tensor files, or to separate its download/cache location from the read-only data root, without monkey-patching the private _get_imdb() helper?
- When preparing Kaggle Datasets, do you generally avoid including both an extracted directory and its source archive, given Kaggleās server-side archive extraction?
Iām sharing this as a debugging/learning note in case the same combination of Kaggle archive processing and package-specific data loaders trips up someone else. Iād appreciate suggestions.
References:
- Kaggle Datasets documentation: https://www.kaggle.com/docs/datasets
- Kaggle Notebooks documentation: https://www.kaggle.com/docs/notebooks
- ISLP Chapter 10 lab: https://intro-stat-learning.github.io/ISLP/labs/Ch10-deeplearning-lab.html
- ISLP 0.5.0 on PyPI: https://pypi.org/project/ISLP/0.5.0/