【问题标题】:Uploading and labeling pairs of photos上传和标记照片对
【发布时间】:2020-08-13 11:02:30
【问题描述】:

我创建了一个 ResNet18 来检测 2 个人是否是兄弟姐妹,通过给出每个人的图像(模型的 input_size = 2)。 我需要创建我的数据集,我将在其中指定哪对是兄弟姐妹。

我试过了:

training_set = train_datagen.flow_from_directory('training',
                                                 target_size=(28,28),
                                                 batch_size=32,
                                                 class_mode='binary')

我得到了 training_set.classes array([0, 0, 0, 0, 1, 1, 1, 1])

用于 training_set.filenames

 'false\\false1\\_DSC5763.jpg',
 'false\\false2\\_DSC5751.jpg',
 'false\\false2\\_DSC5760.jpg',
 'siblings\\siblings1\\_DSC5751.jpg',
 'siblings\\siblings1\\_DSC5755_1.jpg',
 'siblings\\siblings2\\_DSC5760.jpg',
 'siblings\\siblings2\\_DSC5763.jpg'

就我的目的而言,training_set.classes 应该是array([0, 0, 1, 1])。 我该怎么做?

【问题讨论】:

  • 假数据对的数据如何,您是否有一对被标记为非同级的图像?还是您只有一对兄弟姐妹,而任何其他随机对都暗示不是兄弟姐妹?
  • 再次确认您是否有负面案例? IE。你有类似person1 person2 not_sibling 的东西吗?或者只是正面案例,即所有行都包含一对实际上是兄弟姐妹的人。
  • 我有一张 180 个人的照片和一个 excel 文件,它告诉我哪些对是兄弟姐妹或不是兄弟姐妹。这是 excel 文件的标题和行的样子: ................................... ................................unique ID; siblings?; first picture; second picture; 0003_0001 1 3/DSC5751 1/DSC5755_1
  • 那么,我要问的是你有没有siblings?0 的条目?
  • 是的,我有兄弟姐妹在哪里 0

标签: machine-learning image-processing keras deep-learning


【解决方案1】:

我完成了我的项目,我想回来发布我找到的答案。我正在尝试分类两个人是否是兄弟姐妹。

#Lists used for creating the dataset
categories = []
first_img= []
second_img = []

#Parsing throw the images and making 2 arrays
for filename in filenames:
    category = filename.split('.')[0]

    #Each pair is named <sibling/false>+<nr_of_pair>+0/1
    if 'sibling' in category:
        if filename.split('_')[1][0] == '0':
            first_img.append(filename)
            categories.append(1)
        else:
            second_img.append(filename)
    else:
        if filename.split('_')[1][0] == '0':
            first_img.append(filename)
            categories.append(0)
        else:
            second_img.append(filename)

#dataset of the first individual of the pair and it's label      
df1 = pd.DataFrame({
    'filename': first_img,
    'category': categories
}).astype('str')

#dataset of the second individual of the pair and it's label  
df2 =pd.DataFrame({
    'filename': second_img,
    'category': categories
}).astype('str')

对于 fit_generator 我使用了该函数。

def generate_generator_multiple(datagen):
    train_generator1 = datagen.flow_from_dataframe(df1, 
                                                        "../train/input/", 
                                                        x_col='filename',
                                                        y_col='category',
                                                        class_mode='binary',
                                                        target_size=(image_size1, image_size2),
                                                        batch_size = batch_size)

    train_generator2 = datagen.flow_from_dataframe(df2, 
                                                        "../train/input/", 
                                                        x_col='filename',
                                                        y_col='category',
                                                        class_mode='binary',
                                                        target_size=(image_size1, image_size2),
                                                        batch_size = batch_size)
    while True:
            X1i = train_generator1.next()
            X2i = train_generator2.next()
            yield [X1i[0], X2i[0]], X2i[1]  #Yield both images and their mutual

datagen 是一个 ImageDataGenerator 对象

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多