Small amount of duplicates and double extensions

#11
by yuzaboto - opened

When processing the data found that there are a few types of duplicates.
A small amount of images in "original" also exist in "recent"
For example:
danbooru2023/recent/1400/6973400.jpg
danbooru2023/original/0400/6973400.jpg
(Think there is a small overlap in the range of ids "original" and "recent" cover)

Also some images appear twice with different extensions. For example:
danbooru2023/original/0400/3800400.png
danbooru2023/original/0400/3800400.jpg
(This also happens across parts. For example, the jpg will be in "original" and the png in "recent" or vice versa)

Im only processing files that end with png/jpg/jpeg so there might be other similar issues with other file types.
On the data I have downloaded, found 36970 dupes.

I've attached the code I used while figuring this out, in case its helpful (quality isn't great but should work)

def get_files_in_folder(folder_path):
    file_list = []
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            full_path = os.path.join(root, file)
            file_list.append(full_path)
    return file_list

filePaths=get_files_in_folder("dataset3/danbooru2023")
totalNumOfDups=0
filePaths3={}
for itemPath in filePaths:
    imageId=int(os.path.basename(itemPath).split(".")[0])
    if(imageId in filePaths3):
        otherPath=filePaths3[imageId]
        if(itemPath.endswith(".png") and (not otherPath.endswith(".png"))):
            print("------------")
            print(itemPath)
            print(otherPath)
            print("would remove: "+otherPath)
            filePaths3[imageId]=itemPath
            totalNumOfDups+=1
        elif(otherPath.endswith(".png") and (not itemPath.endswith(".png"))):
            print("------------")
            print(itemPath)
            print(otherPath)
            print("would remove: "+itemPath)
            totalNumOfDups+=1
        elif(("original/" in itemPath) and (not ("original/" in otherPath))):
            print("------------")
            print(itemPath)
            print(otherPath)
            print("would remove: "+otherPath)
            filePaths3[imageId]=itemPath
            totalNumOfDups+=1
        elif(("original/" in otherPath) and (not ("original/" in itemPath))):
            print("------------")
            print(itemPath)
            print(otherPath)
            print("would remove: "+itemPath)
            totalNumOfDups+=1
        else:
            print("error")
        pass
    else:
        filePaths3[imageId]=itemPath
print(totalNumOfDups)

edit: there is a small amount of dupes that this code doesnt handle and just prints error, like the same image appearing once with jpg and once jpeg.

Sign up or log in to comment