-
-
Save tyoc213/3e82f91095038f06f5b8d89edc9d70d1 to your computer and use it in GitHub Desktop.
exception because incorrect format for dataloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% | |
from fastai2.vision.all import * | |
# in the same folder I have downloaded with: kaggle competitions download -c digit-recognizer | |
path = untar_data("file://digit-recognizer.zip", dest=".") | |
print(path) | |
print(path.ls()) | |
#%% | |
import pandas as pd | |
df = pd.read_csv(Path(path)/"train.csv", header='infer') | |
df.head() | |
#%% | |
df.describe() | |
# %% | |
imagenes = df.iloc[:,1:].apply(lambda x: x.values, axis=1).values | |
labels = df.iloc[:,:1].apply(lambda x: x.values[0], axis=1) | |
len(imagenes), len(labels) | |
# %% | |
from PIL import Image | |
from matplotlib import cm | |
def get_image(csv_row): | |
img = csv_row.reshape(28,28) | |
x = cm.gist_earth(img)*255 | |
return Image.fromarray(np.uint8(x)) | |
get_image(imagenes[110]) | |
# %% | |
def get_my_images(uno): | |
print(f"get_my_images {uno}") | |
print(uno) | |
l = L() | |
for idx, i in enumerate(imagenes): | |
img = get_image(i) | |
# return i | |
# l.append({'img': img, 'lbl':labels[idx]}) | |
# img.some = labels[idx] | |
# l.append(img) | |
# x = torch.from_numpy(i) | |
# x.numero = labels[idx] | |
# l.append(x) | |
p = TensorImage(img) | |
p.numero = labels[idx] | |
l.append(p) | |
return l | |
def get_my_labels(fname): | |
return fname.numero | |
dblock = DataBlock(get_items = get_my_images, | |
get_y = get_my_labels) | |
dsets = dblock.datasets("digit-recognizer") | |
dsets.train[10] | |
# %% | |
########## RUN TO THIS CELL ########################## | |
########## RUN TO THIS CELL ########################## | |
########## RUN TO THIS CELL ########################## | |
########## RUN TO THIS CELL ########################## | |
# | |
dls = dblock.dataloaders("digit-recognizer") | |
dls.show_batch() # <-- AttributeError: 'Tensor' object has no attribute 'show' from fastai2/data/core.py line 18 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The complete output is