Deep learning 如何在python中删除mein数据集中相同数量的照片

Deep learning 如何在python中删除mein数据集中相同数量的照片,deep-learning,fast-ai,Deep Learning,Fast Ai,嗨,我用python制作了一个食物数据框,每个食物有1000张照片。 我想放一些食物的照片,比如冰淇淋100张照片,蛋卷100张照片。。。等) 因此,必须删除每个类别的100张图片 我试图删除每个数据帧的图片,但我这样做了,我应该重复这100次。。。如何使用简短语法解决此问题?添加您尝试删除图片的代码。我添加了我尝试删除的代码 def get_df_from_file(path, is_valid): img_df = pd.read_csv(path, delimiter='/'

嗨,我用python制作了一个食物数据框,每个食物有1000张照片。 我想放一些食物的照片,比如冰淇淋100张照片,蛋卷100张照片。。。等)

因此,必须删除每个类别的100张图片
我试图删除每个数据帧的图片,但我这样做了,我应该重复这100次。。。如何使用简短语法解决此问题?

添加您尝试删除图片的代码。我添加了我尝试删除的代码
def get_df_from_file(path, is_valid):   
    img_df = pd.read_csv(path, delimiter='/', header=None, names=['label', 'name'])
    # Append .jpg extension to all file names
    img_df['name'] = img_df['label'].astype(str) + '/' + img_df['name'].astype(str) + '.jpg'

    # Join extracted values and set is_valid
    img_df['is_valid'] = is_valid
    #img_df=img_df.loc[(img_df['label'] == 'ramen')]
    
    return img_df
 
   
# Load the train set
train_df = get_df_from_file(path/'train.txt', False)
print(train_df.shape)

# Load the validation set
test_df = get_df_from_file(path/'test.txt', True)
print(test_df.shape)

# Concatenate train and test sets
image_df = pd.concat([train_df, test_df])
display(image_df.sample(10))
print(image_df.shape)
train_df0=train_df.loc[(train_df['label'] == df.label[0])]
drop_indices = np.random.choice(train_df0.index,50, replace=False)
train_df0 = train_df0.drop(drop_indices)

train_df1=train_df.loc[(train_df['label'] == df.label[1])]
drop_indices = np.random.choice(train_df1.index,50, replace=False)
train_df1 = train_df1.drop(drop_indices)

train_df2=train_df.loc[(train_df['label'] == df.label[2])]
drop_indices = np.random.choice(train_df2.index,50, replace=False)
train_df2 = train_df2.drop(drop_indices)

train_df3=train_df.loc[(train_df['label'] == df.label[3])]
drop_indices = np.random.choice(train_df3.index,50, replace=False)
train_df3 = train_df3.drop(drop_indices)

train_df4=train_df.loc[(train_df['label'] == df.label[4])]
drop_indices = np.random.choice(train_df4.index,50, replace=False)
train_df4 = train_df4.drop(drop_indices)

train_df5=train_df.loc[(train_df['label'] == df.label[5])]
drop_indices = np.random.choice(train_df5.index,50, replace=False)
train_df5 = train_df5.drop(drop_indices)