0

我正在关注一个用于人脸识别的连体网络示例,它只使用两个类每个类有 3 个图像(即总共 6 个图像)。如何修改以下代码以读取并标记为6 个图像类每个类 10 个图像(即总共 60 个图像)?

sub_dir_list = os.listdir( dir_path )
images = list()
labels = list()
for i in range( len( sub_dir_list ) ):
    label = i
    image_names = os.listdir( os.path.join(dir_path , sub_dir_list[i]) )
    for image_path in image_names:
        path = os.path.join(dir_path , sub_dir_list[i] , image_path )
        try :
            image = Image.open(path)
            resize_image = image.resize((dimen, dimen))
            array_ = list()
            for x in range(dimen):
                sub_array = list()
                for y in range(dimen):
                    sub_array.append(resize_image.load()[x, y])
                array_.append(sub_array)
            image_data = np.array(array_)
            image = np.array(np.reshape(image_data, (dimen, dimen, 3))) / 255
            images.append(image)
            labels.append(label)
        except:
            print( 'WARNING : File {} could not be processed.'.format( path ) )

images = np.array( images )

samples_1 = list()
samples_2 = list()
labels = list()
for i in range( 6 ) :
    for j in range( 6 ) :
        samples_1.append( images[i] )
        samples_2.append( images[j] )
        if i < 3 :
            if j < 3 :
                labels.append( 1 )
            else:
                labels.append( 0 )
        else :
            if j > 2 :
                labels.append( 1 )
            else:
                labels.append( 0 )

X1 = np.array( samples_1  )
X2 = np.array( samples_2 )
Y = np.array( labels )
4

0 回答 0