Skip to content

Instantly share code, notes, and snippets.

@Justin-Heer
Created August 16, 2020 16:19
Show Gist options
  • Save Justin-Heer/dcddcc86a41327ac530b0ce398d076c9 to your computer and use it in GitHub Desktop.
Save Justin-Heer/dcddcc86a41327ac530b0ce398d076c9 to your computer and use it in GitHub Desktop.
extract_features_dir
def extract_features_dir(ddir, cnn_model):
# check the existence of the directory
if not os.path.exists(ddir):
raise ValueError('The directory "{}" does not exist!'.format(ddir))
# create an empty list to hold the result
features = []
# get the list of image dirs in this
iDirNames = [os.path.join(ddir, idir) for idir in os.listdir(ddir)]
# sort the file names
iDirNames.sort(key= lambda x: int(os.path.basename(x)[1:]))
print(iDirNames)
# extract features from each video
for iDirName in iDirNames:
print(f'Current Video:{iDirName}')
feature = extract_features(iDirName, cnn_model)
if feature.size != 0:
features.append(feature)
# return the results as a ndarray
return np.array(features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment