Issue with generic path
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9k
- Forks
- 1.5k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 3
Description
Hi, I am trying to profile a program. When I ran it with python3, the program could run smoothly. However, it failed when I tried to profile it. Here is my error message:
Traceback (most recent call last):
File "test.py", line 57, in <module>
if not os.path.exists(filename):
File "/home/yingj4/anaconda3/lib/python3.7/genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
==5317== Generated result file: /home/yingj4/Desktop/RITnetForFun/test.sql
Here is the code I tried to profile:
"""
Created on Mon Sep 2 11:37:59 2019
@author: aaa
"""
import torch
from dataset import IrisDataset
from torch.utils.data import DataLoader
import numpy as np
import matplotlib.pyplot as plt
from dataset import transform
import os
from opt import parse_args
from models import model_dict
from tqdm import tqdm
from utils import get_predictions
#%%
"""
The new codes for profiling starts here
@author: Ying
"""
import torch.cuda.profiler as profiler
from apex import pyprof
pyprof.nvtx.init()
torch.autograd.profiler.emit_nvtx()
"""
The new codes for profiling ends here
@author: Ying
"""
if __name__ == '__main__':
args = parse_args()
if args.model not in model_dict:
print ("Model not found !!!")
print ("valid models are:",list(model_dict.keys()))
exit(1)
if args.useGPU:
device=torch.device("cuda")
else:
device=torch.device("cpu")
model = model_dict[args.model]
model = model.to(device)
filename = args.load
if not os.path.exists(filename):
print("model path not found !!!")
exit(1)
model.load_state_dict(torch.load(filename))
model = model.to(device)
model.eval()
test_set = IrisDataset(filepath = 'Semantic_Segmentation_Dataset/',\
split = 'test',transform = transform)
testloader = DataLoader(test_set, batch_size = args.bs,
shuffle=False, num_workers=2)
counter=0
os.makedirs('test/labels/',exist_ok=True)
os.makedirs('test/output/',exist_ok=True)
os.makedirs('test/mask/',exist_ok=True)
with torch.no_grad():
for i, batchdata in tqdm(enumerate(testloader),total=len(testloader)):
img,labels,index,x,y= batchdata
data = img.to(device)
output = model(data)
predict = get_predictions(output)
for j in range (len(index)):
np.save('test/labels/{}.npy'.format(index[j]),predict[j].cpu().numpy())
try:
plt.imsave('test/output/{}.jpg'.format(index[j]),255*labels[j].cpu().numpy())
except:
pass
pred_img = predict[j].cpu().numpy()/3.0
inp = img[j].squeeze() * 0.5 + 0.5
img_orig = np.clip(inp,0,1)
img_orig = np.array(img_orig)
combine = np.hstack([img_orig,pred_img])
plt.imsave('test/mask/{}.jpg'.format(index[j]),combine)
os.rename('test',args.save)
Here is the related code in genericpath.py:
Does a path exist?
This is false for dangling symbolic links on systems that support them.
def exists(path):
"""Test whether a path exists. Returns False for broken symbolic links"""
try:
os.stat(path)
except OSError:
return False
return True
Thank you!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at test.py line 57, where os.path.exists receives filename, and trace args.load back through parse_args. Compare the profiling setup using apex.pyprof and torch.autograd.profiler with the non-profiled run. Done means identifying whether Apex causes the None path or whether the reported failure is in the user's argument handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100