SoFunction
Updated on 2024-11-12

Example code for python to batch check if the number of lines in two corresponding txt files is the same

In doing target detection for deep learning, after we test the dataset, we can use batch to check the label files under the two data files to see if their rows are the same, so that we can determine whether there is any leakage, so we don't have to look at one picture after another.

在这里插入图片描述

Comparing the number of lines in the two labeled files reveals if there are any missed checks. (The comparison is between labeled and trained labels)

The code is as follows

#coding=utf-8
import os, glob
import numpy as np

path1 = 'temp//1//'
path2 = 'temp//2//'

file_one_list = (path1 + "*.txt")
file_two_list = (path2 + "*.txt")
print(len(file_one_list))

for item in (file_one_list):
 base_name = (item)
 with open(item,'r') as f:
  lines_one=()
 cur_file_path = (path2, base_name)
 if (cur_file_path):
  with open(cur_file_path,'r') as f:
   lines_two=()
  if len(lines_one)!=len(lines_two):
   print("Detection box does not correspond:",base_name)
 else:
  print("Not in the file.",base_name)

summarize

to this article on python batch check two corresponding txt file line is consistent with the article is introduced to this, more related python batch check txt file content, please search for my previous posts or continue to browse the following related articles I hope that you will support me in the future more!