minor modifications in the util function recently added
@@ -2145,7 +2145,7 @@ def create_metadata_table(conn, folder='', task='image_classification',
task : str
Specifies the task where we are creating the metadata table
Default: image_classification
- extensions_to_filder : list of extensions in str
+ extensions_to_filter : list of extensions in str
Specifies the extensions that we are interested in while traversing the folders.
caslib : str
Specifies the caslib of the folder
@@ -2158,18 +2158,22 @@ def create_metadata_table(conn, folder='', task='image_classification',
'''
tasks = ['image_classification']
+ rel_path = ''
if task in tasks:
if caslib is not None:
if not conn.table.querycaslib(caslib=caslib)[caslib]:
raise DLPyError('caslib='+caslib+' cannot be found in the server.')
r = conn.table.caslibinfo(caslib=caslib)
- folder = os.path.join( r.CASLibInfo.Path[0], folder)
+ rel_path = r.CASLibInfo.Path[0]
+ folder = os.path.join(rel_path, folder)
if task is 'image_classification':
- return create_image_classification_metadata_table( conn, folder, extensions_to_filter, output_name)
+ return create_image_classification_metadata_table(conn, folder,
+ extensions_to_filter, output_name, rel_path)
else:
raise DLPyError('We do not support this task yet, supported tasks are as follows: '+str(tasks))
-def create_image_classification_metadata_table( conn, folder, extensions_to_filter, output_name):
+
+def create_image_classification_metadata_table(conn, folder, extensions_to_filter, output_name, rel_path):
'''
Creates a metadata table from the specified folder or folder and caslib information.
The code traverses the given folder recursively and creates a dataframe, which is then uploaded
@@ -2183,10 +2187,12 @@ def create_image_classification_metadata_table( conn, folder, extensions_to_filt
Specifies the CAS connection
folder : string
Specifies the location of the images.
- extensions_to_filder : list of extensions in str
+ extensions_to_filter : list of extensions in str
Specifies the extensions that we are interested in while traversing the folders.
output_name : str
Specifies the name of the output cas table
+ rel_path : str
+ Specifies the path of the caslib, this will be used to extract the relative path of an input file.
Returns
-------
@@ -2208,9 +2214,18 @@ def create_image_classification_metadata_table( conn, folder, extensions_to_filt
absolute_path = os.path.join(root, f)
dirname = os.path.dirname( absolute_path)
basename = os.path.basename( dirname)
- data.append([absolute_path, f, basename, count])
+ fe = os.path.splitext(f)
+ fee = ''
+ if len(fe) > 1:
+ fee = fe[0]
+ rp = ''
+ if len(rel_path) > 0:
+ s = absolute_path.split(rel_path)
+ if len(s) > 1:
+ rp = s[1]
+ data.append([absolute_path, rp, f, fee, basename, count])
count +=1
- df = pd.DataFrame(data, columns=['_filePath_', '_fileName_', '_label_', '_id_'])
+ df = pd.DataFrame(data, columns=['_filePath_', '_relativePath_', '_fileName_', '_fName_', '_label_', '_id_'])
return conn.upload_frame(df, casout=dict(name=output_name, replace=True))
