SkinToneClassifier icon indicating copy to clipboard operation
SkinToneClassifier copied to clipboard

[🐛 BUG] Errors appearing in result.csv

Open cleong110 opened this issue 5 months ago • 1 comments

Describe the bug

I gave stone CLI util a folder, one of which was completely black, here it is: Image

file,image type,face id,dominant 1,percent 1,dominant 2,percent 2,skin tone,tone label,accuracy(0-100)
<the path to the file was here....>/frame_00000.png: OpenCV(4.12.0) /io/opencv/modules/core/src/kmeans.cpp:243: error: (-2:Unspecified error) in function 'double cv::kmeans(cv::InputArray, int, cv::InputOutputArray, cv::TermCriteria, int, int, cv::OutputArray)'
> There can't be more clusters than elements (expected: 'N >= K'), where
>     'N' is 0
> must be greater than or equal to
>     'K' is 2

frame_00240.png,bw,NA,#7D624F,0.57,#D1AB71,0.43,#808080,BI,79.66
frame_00480.png,bw,NA,#35343A,0.89,#A6796D,0.11,#303030,BN,92.14

The output csv then actually containes the error output.

I expected this to show up in the log, but not in the result.csv

cleong110 avatar Jul 28 '25 10:07 cleong110

Turns out it's still possible to parse this CSV with the following logic:



def read_clean_csv(path: Path) -> tuple[pd.DataFrame, list[tuple[int, str]]]:
    """Read a CSV file, skipping bad lines and returning both the DataFrame and the list of skipped rows."""
    valid_rows = []
    bad_rows = []

    with open(path, encoding="utf-8") as f:
        header = f.readline().strip().split(",")
        for lineno, line in enumerate(f, start=2):
            row = line.strip().split(",")
            if len(row) == len(header):
                valid_rows.append(row)
            else:
                bad_rows.append((lineno, line.strip()))

    df = pd.DataFrame(valid_rows, columns=header)
    return df, bad_rows


cleong110 avatar Jul 28 '25 10:07 cleong110