@@ -534,7 +534,7 @@ def imagenet(info, root, config):
534
534
devkit_root .mkdir ()
535
535
data_root = devkit_root / "data"
536
536
data_root .mkdir ()
537
- with open (data_root / "ILSVRC2012_validation_ground_truth.txt" , "w" ) as file :
537
+ with open (data_root / "ILSVRC2012_validation_ground_truth.txt" , "w" , newline = "" ) as file :
538
538
for label in torch .randint (0 , len (wnids ), (num_samples ,)).tolist ():
539
539
file .write (f"{ label } \n " )
540
540
make_tar (root , f"{ devkit_root } .tar.gz" , devkit_root , compression = "gz" )
@@ -672,7 +672,7 @@ def _make_split_files(cls, root_map):
672
672
}
673
673
674
674
for split , ids in ids_map .items ():
675
- with open (root_map [split ] / f"{ split } .txt" , "w" ) as fh :
675
+ with open (root_map [split ] / f"{ split } .txt" , "w" , newline = "" ) as fh :
676
676
fh .writelines (f"{ id } \n " for id in ids )
677
677
678
678
return sorted (set (itertools .chain (* ids_map .values ()))), {split : len (ids ) for split , ids in ids_map .items ()}
@@ -738,11 +738,11 @@ def semeion(info, root, config):
738
738
739
739
images = torch .rand (num_samples , 256 )
740
740
labels = one_hot (torch .randint (len (info .categories ), size = (num_samples ,)))
741
- with open (root / "semeion.data" , "w" ) as fh :
741
+ with open (root / "semeion.data" , "w" , newline = "" ) as fh :
742
742
for image , one_hot_label in zip (images , labels ):
743
743
image_columns = " " .join ([f"{ pixel .item ():.4f} " for pixel in image ])
744
744
labels_columns = " " .join ([str (label .item ()) for label in one_hot_label ])
745
- fh .write (f"{ image_columns } { labels_columns } \n " )
745
+ fh .write (f"{ image_columns } { labels_columns } \r \ n " )
746
746
747
747
return num_samples
748
748
@@ -780,7 +780,7 @@ def _make_split_files(cls, root, *, year, trainval):
780
780
task_folder = split_folder / task_sub_folder
781
781
task_folder .mkdir (parents = True , exist_ok = True )
782
782
for split , ids in ids_map .items ():
783
- with open (task_folder / f"{ split } .txt" , "w" ) as fh :
783
+ with open (task_folder / f"{ split } .txt" , "w" , newline = "" ) as fh :
784
784
fh .writelines (f"{ id } \n " for id in ids )
785
785
786
786
return sorted (set (itertools .chain (* ids_map .values ()))), {split : len (ids ) for split , ids in ids_map .items ()}
@@ -857,7 +857,7 @@ def voc(info, root, config):
857
857
class CelebAMockData :
858
858
@classmethod
859
859
def _make_ann_file (cls , root , name , data , * , field_names = None ):
860
- with open (root / name , "w" ) as file :
860
+ with open (root / name , "w" , newline = "" ) as file :
861
861
if field_names :
862
862
file .write (f"{ len (data )} \r \n " )
863
863
file .write (" " .join (field_names ) + "\r \n " )
@@ -971,13 +971,13 @@ def dtd(info, root, _):
971
971
meta_folder = data_folder / "labels"
972
972
meta_folder .mkdir ()
973
973
974
- with open (meta_folder / "labels_joint_anno.txt" , "w" ) as file :
974
+ with open (meta_folder / "labels_joint_anno.txt" , "w" , newline = "" ) as file :
975
975
for cls , image_ids in image_ids_per_category .items ():
976
976
for image_id in image_ids :
977
977
joint_categories = random .choices (
978
978
list (categories - {cls }), k = int (torch .randint (len (categories ) - 1 , ()))
979
979
)
980
- file .write (" " .join ([image_id , * sorted ([cls , * joint_categories ])]) + "\n " )
980
+ file .write (" " .join ([image_id , * sorted ([cls , * joint_categories ])]) + " \n " )
981
981
982
982
image_ids = list (itertools .chain (* image_ids_per_category .values ()))
983
983
splits = ("train" , "val" , "test" )
@@ -986,7 +986,7 @@ def dtd(info, root, _):
986
986
random .shuffle (image_ids )
987
987
for offset , split in enumerate (splits ):
988
988
image_ids_in_config = image_ids [offset :: len (splits )]
989
- with open (meta_folder / f"{ split } { fold } .txt" , "w" ) as file :
989
+ with open (meta_folder / f"{ split } { fold } .txt" , "w" , newline = "" ) as file :
990
990
file .write ("\n " .join (image_ids_in_config ) + "\n " )
991
991
992
992
num_samples_map [info .make_config (split = split , fold = str (fold ))] = len (image_ids_in_config )
@@ -1104,7 +1104,7 @@ def generate(self, root):
1104
1104
num_samples_map = {}
1105
1105
for offset , split in enumerate (splits ):
1106
1106
split_and_classification_anns_in_split = split_and_classification_anns [offset :: len (splits )]
1107
- with open (anns_folder / f"{ split } .txt" , "w" ) as file :
1107
+ with open (anns_folder / f"{ split } .txt" , "w" , newline = "" ) as file :
1108
1108
writer = csv .writer (file , delimiter = " " )
1109
1109
for split_and_classification_ann in split_and_classification_anns_in_split :
1110
1110
writer .writerow (split_and_classification_ann )
@@ -1171,7 +1171,7 @@ def _make_archive(cls, root):
1171
1171
image_files = cls ._make_images (images_folder )
1172
1172
image_ids = list (range (1 , len (image_files ) + 1 ))
1173
1173
1174
- with open (archive_folder / "images.txt" , "w" ) as file :
1174
+ with open (archive_folder / "images.txt" , "w" , newline = "" ) as file :
1175
1175
file .write (
1176
1176
"\n " .join (
1177
1177
f"{ id } { path .relative_to (images_folder ).as_posix ()} " for id , path in zip (image_ids , image_files )
@@ -1181,10 +1181,10 @@ def _make_archive(cls, root):
1181
1181
split_ids = torch .randint (2 , (len (image_ids ),)).tolist ()
1182
1182
counts = Counter (split_ids )
1183
1183
num_samples_map = {"train" : counts [1 ], "test" : counts [0 ]}
1184
- with open (archive_folder / "train_test_split.txt" , "w" ) as file :
1184
+ with open (archive_folder / "train_test_split.txt" , "w" , newline = "" ) as file :
1185
1185
file .write ("\n " .join (f"{ image_id } { split_id } " for image_id , split_id in zip (image_ids , split_ids )))
1186
1186
1187
- with open (archive_folder / "bounding_boxes.txt" , "w" ) as file :
1187
+ with open (archive_folder / "bounding_boxes.txt" , "w" , newline = "" ) as file :
1188
1188
file .write (
1189
1189
"\n " .join (
1190
1190
" " .join (
@@ -1237,7 +1237,7 @@ def _make_splits(cls, root, image_files):
1237
1237
image_files_in_split = image_files [offset :: len (splits )]
1238
1238
1239
1239
split_file = split_folder / f"{ split } .txt"
1240
- with open (split_file , "w" ) as file :
1240
+ with open (split_file , "w" , newline = "" ) as file :
1241
1241
file .write (
1242
1242
"\n " .join (
1243
1243
sorted (
0 commit comments