Primary competition visual

CGIAR Crop Damage Classification Challenge

Helping Africa
$10 000 USD
Completed (~2 years ago)
Classification
1148 joined
347 active
Starti
Oct 27, 23
Closei
Jan 28, 24
Reveali
Jan 28, 24
User avatar
Eduardo Mondlane University
FileNotFound Exception
Help · 11 Jan 2024, 10:06 · 16

I can't even import the images. Every time I do this, a FileNotFound error appears.

I try to load images using ImageDataLoaders.from_df() and It always raise an Exception (FileNot FoundError) even though the file exists in image folder.

Discussion 16 answers
User avatar
brendentaylor22

I had a similar experience. Are you using Colab/Kaggle or running it locally?

What helped me figure out my problem was to copy/paste the file that's not found and try to plot it in Python using the path directly. Turns out my extracting of the zip file hadn't completed properly and so the file genuinely wasn't there.

11 Jan 2024, 11:09
Upvotes 1
User avatar
Eduardo Mondlane University

I tried both Kaggle and Colab. The error was the same.

I will try your tip. Thanks a lot.

User avatar
Ahmed_Mandour

can u copy the error so we can help you ?

12 Jan 2024, 07:34
Upvotes 1
User avatar
Eduardo Mondlane University
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-41-66ea6d5a4411> in <cell line: 2>()
      1 train_data = prepare_train_data(train, skf, '/drive/MyDrive/Colab Notebooks/Files/images')
----> 2 train_model(train_data)

16 frames

/usr/local/lib/python3.10/dist-packages/PIL/Image.py in open(fp, mode, formats)
   3225 
   3226     if filename:
-> 3227         fp = builtins.open(filename, "rb")
   3228         exclusive_fp = True
   3229
FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Colab Notebooks/Files/images//drive/MyDrive/Colab Notebooks/Files/images/d036341be8d6cd59851cb80bcc9a70cc9fbdba30.jpg'
User avatar
Ahmed_Mandour
of course this is not you file paths '/content/drive/MyDrive/Colab Notebooks/Files/images//drive/MyDrive/Colab Notebooks/Files/images/d036341be8d6cd59851cb80bcc9a70cc9fbdba30.jpg'

if you use colab, where do you save your image ? just give me the absoulute path
User avatar
Ahmed_Mandour

and what you put in this fn( ImageDataLoaders.from_df() )

User avatar
Eduardo Mondlane University

fn_col = 'path'

There is the code bellow:

dls = ImageDataLoaders.from_df(

df,

path=f'{DATASET_DIR}/images',

valid_col='is_valid',

seed=SEED, #seed

fn_col='path',

label_col='target', #label is in the first column of the DataFrame

label_delim=' ',

y_block=MultiCategoryBlock, #The type of target

bs=BATCH_SIZE, #pass in batch size

num_workers=NUM_WORKER,

item_tfms=Resize(IMGSZ), #pass in item_tfms

batch_tfms=setup_aug_tfms([Brightness(), Contrast(), Flip(), Rotate()]))

User avatar
Eduardo Mondlane University

I saved all the images on Google Drive.

User avatar
Ahmed_Mandour

delete this line path=f'{DATASET_DIR}/images', and see

User avatar
Eduardo Mondlane University

I'm sorry, but it still gives the same error.

User avatar
Ahmed_Mandour

ok, copy the error now

User avatar
Eduardo Mondlane University

I finally managed to solve the problem thanks to your recommendations. Thank you very much.

User avatar
Ahmed_Mandour

waiting you in the top of leaderboard

hai i also get that similar error ,plz help me to solve this , i am trying to run the starter notebook in kaggle but getting below error 

"[Errno 2] No such file or directory: './kaggle/input/zindidata/images/d036341be8d6cd59851cb80bcc9a70cc9fbdba30.jpg'"


how to remove that dot infront of the path ,because its seraching the data in the root dir which is kaggle/output , but data is in kaggle/input
even if i try to change the root dir into kaggle/input getting some error respective to  dependencies
User avatar
Eduardo Mondlane University
the following helped me:

data  = ImageDataLoaders.from_df(path='/kaggle/input/zindidata/images/',
df=train,
folder="images",
label_delim=None,
valid_pct=0.2,
seed=100,
fn_col=2,
label_col=1,
suffix='',
#ds_tfms=transformations,
size=512,
bs=64,
val_bs=32,
)

Ensure that the DataFrame you’re passing to ImageDataLoaders.from_df() contains the correct paths to the images. The paths should be relative to your current working directory or absolute paths. For example:

import pandas as pd

data = {
    'filename': ['images/image1.jpg', 'images/image2.jpg'],
    'label': ['cat', 'dog']
}
df = pd.DataFrame(<snow rider 3d data)

22 Oct 2024, 03:06
Upvotes 0