Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm trying to run a code that part of it searches for a folder that contains text files and converts it to a ply format files. my problem is that the for loop that is attached is not working! Accordingly the data_list is not appending any thing. I used 'os.listdir(anno_path)' to see the anno_path it's using and it showed me an error that the used file is not found and I am definitely sure that the path is correct.
Any help please!
```
dataset_path = 'Research/Codes/Randlanet/data/S3DIS/Stanford3dDataset_v1.2_Aligned_Version'
anno_paths = [line.rstrip() for line in open(join(BASE_DIR, 'meta/anno_paths.txt'))]
anno_paths = [join(dataset_path, p) for p in anno_paths]
gt_class = [x.rstrip() for x in open(join(BASE_DIR, 'meta/class_names.txt'))]
gt_class2label = {cls: i for i, cls in enumerate(gt_class)}

sub_grid_size = 0.04
original_pc_folder = join(dirname(dataset_path), 'original_ply')
sub_pc_folder = join(dirname(dataset_path), 'input_{:.3f}'.format(sub_grid_size))
os.mkdir(original_pc_folder) if not exists(original_pc_folder) else None
os.mkdir(sub_pc_folder) if not exists(sub_pc_folder) else None
out_format = '.ply'

def convert_pc2ply(anno_path, save_path):
    os.listdir(anno_path)
data_list = []
    for f in glob.glob(join(anno_path, '*.txt')):
        class_name = os.path.basename(f).split('_')[0]
        if class_name not in gt_class:  # note: in some room there is 'stairs' class..
           class_name = 'clutter'
        pc = pd.read_csv(f, header=None, delim_whitespace=True).values
        labels = np.ones((pc.shape[0], 1)) * gt_class2label[class_name]
        data_list.append(np.concatenate([pc, labels], 1))  # Nx7
        print(data_list) #To visualize the problem
    pc_label = np.concatenate((data_list, [0]))
    xyz_min = np.amin(pc_label, axis=0)[0:3]

the error:
<pre>Research/Codes/Randlanet/data/S3DIS/Stanford3dDataset_v1.2_Aligned_Version/Area_1/conferenceRoom_1/Annotations
Traceback (most recent call last):
  File "data_prepare_s3dis.py", line 76, in <module>
    convert_pc2ply(annotation_path, join(original_pc_folder, out_file_name))
  File "data_prepare_s3dis.py", line 29, in convert_pc2ply
    os.listdir(anno_path)
FileNotFoundError: [Errno 2] No such file or directory: 'Research/Codes/Randlanet/data/S3DIS/Stanford3dDataset_v1.2_Aligned_Version/Area_1/conferenceRoom_1/Annotations'


What I have tried:

I tried switching back/forward slashes in the data_path and there was no use
Posted
Updated 8-Oct-21 1:34am
v2
Comments
Richard MacCutchan 30-Sep-21 8:37am    
The error message is telling you why.
Youssef Hany 2021 30-Sep-21 12:43pm    
And I explained that this directory actually presents!
Richard MacCutchan 1-Oct-21 3:23am    
Well that is not what the error message says.

Probably, it's your indentation.
Python is a silly language: indentation is very important because it not only indicates to the reader what is going on (as in sensible languages) is also delimits the start and end of blocks of code. Code which is indented to the same level forms a "block of code", and it ends when a "Less indented" line is encountered.
So in this code:
def convert_pc2ply(anno_path, save_path):
    os.listdir(anno_path)
data_list = []
    for f in glob.glob(join(anno_path, '*.txt')):
Only one line is inside the function convert_pc2ply, all the rest is part of the main code.
And since the function is never called in that fragment, the os.listdir is not called either and ends up empty when you try to use it.

Indent the data_list line, and it might start to work.
 
Share this answer
 
Comments
Youssef Hany 2021 30-Sep-21 12:41pm    
@originalgriff
I tried but it keeps giving me the same error
Dave Kreskowiak 8-Oct-21 7:52am    
It's telling you the path you're telling the code to use does not exist.

This is probably because you're ASSUMING something the code is not. Always use fully qualified paths to files. That means starting with the drive letter, and building the path to the file you want.
try to define the BASE_DIR in your script, then trey to write join as 'str'.join(BASE_DIR)
and so on
best
 
Share this answer
 
Last line in error report may be an indication:
FileNotFoundError: [Errno 2] No such file or directory: 'Research/Codes/Randlanet/data/S3DIS/Stanford3dDataset_v1.2_Aligned_Version/Area_1/conferenceRoom_1/Annotations'

There is not much we can do for you.
You are using a relative path, make sure you are in expected directory and make sure file exist.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900