Skip to content

Commit

Permalink
Fixed file descriptor leak
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanSeriesX committed Oct 30, 2023
1 parent c6eccec commit c4ebe23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ def __getitem__(self, idx):
if self.transform:
sample = self.transform(sample)

image.close()
label.close()

return sample
4 changes: 4 additions & 0 deletions u2net_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def get_args():
def get_device():
if torch.cuda.is_available():
print("NVIDIA CUDA acceleration enabled")
torch.multiprocessing.set_start_method("spawn")
return torch.device("cuda:0")
elif torch.backends.mps.is_available():
print("Apple Metal Performance Shaders acceleration enabled")
torch.multiprocessing.set_start_method("fork")
return torch.device("mps")
else:
print("No GPU acceleration :/")
Expand Down Expand Up @@ -197,6 +199,8 @@ def main():
args = get_args()
device = get_device()

# subprocess.run(["ulimit", "-n", "4096"], shell=True, check=True)

tra_image_dir = args.tra_image_dir
tra_label_dir = args.tra_label_dir
epoch_num = args.epoch_num
Expand Down

0 comments on commit c4ebe23

Please sign in to comment.