feature.py
def features_2D_predict_generator(sFrameBaseDir:str, sFeatureBaseDir:str, keModel:keras.Model, 
    nFramesNorm:int = 40):
    """
    Used by the MobileNet-LSTM NN architecture.
    The (video) frames (2-dimensional) in sFrameBaseDir are fed into keModel (eg MobileNet without top layers)
    and the resulting features are save to sFeatureBaseDir.
    """

    # do not (partially) overwrite existing feature directory
    #if os.path.exists(sFeatureBaseDir): 
    #    warnings.warn("\nFeature folder " + sFeatureBaseDir + " alredy exists, calculation stopped") 
    #    return

    # prepare frame generator - without shuffling!
    _, h, w, c = keModel.input_shape
    genFrames = FramesGenerator(sFrameBaseDir, 1, nFramesNorm, h, w, c, 
        liClassesFull = None, bShuffle=False)

    print("Predict features with %s ... " % keModel.name)
    nCount = 0
    # Predict - loop through all samples
    for _, seVideo in genFrames.dfVideos.iterrows():
        
        # ... sFrameBaseDir / class / videoname=frame-directory
        sVideoName = seVideo.sFrameDir.split("/")[-1]
        sLabel = seVideo.sLabel
        sFeaturePath = sFeatureBaseDir + "/" + sLabel + "/" + sVideoName + ".npy"

        # check if already predicted
        if os.path.exists(sFeaturePath):
            print("Video %5d: features already extracted to %s" % (nCount, sFeaturePath))
            nCount += 1
            continue

        # get normalized frames and predict feature
        arX, _ = genFrames.data_generation(seVideo)
        arFeature = keModel.predict(arX, verbose=0)

        # save to file
        os.makedirs(sFeatureBaseDir + "/" + sLabel, exist_ok = True)
        np.save(sFeaturePath, arFeature)

        print("Video %5d: features %s saved to %s" % (nCount, str(arFeature.shape), sFeaturePath))
        nCount += 1

    print("%d features saved to files in %s" % (nCount+1, sFeatureBaseDir))
    return

    Used by the MobileNet-LSTM NN architecture.
    The (video) frames (2-dimensional) in sFrameBaseDir are fed into keModel (eg MobileNet without top layers)
    and the resulting features are save to sFeatureBaseDir.
    
Used by the MobileNet-LSTM NN architecture.
The (video) frames (2-dimensional) in sFrameBaseDir are fed into keModel
and the resulting features are save to sFeatureBaseDir.
Used by the MobileNet - LSTM NN architecture . The ( video ) frames ( 2 - dimensional ) in sFrameBaseDir are fed into keModel and the resulting features are save to sFeatureBaseDir .
def features_2D_predict_generator(sFrameBaseDir:str, sFeatureBaseDir:str, keModel:keras.Model, 
    nFramesNorm:int = 40):
    _, h, w, c = keModel.input_shape
    genFrames = FramesGenerator(sFrameBaseDir, 1, nFramesNorm, h, w, c, 
        liClassesFull = None, bShuffle=False)
    print("Predict features with %s ... " % keModel.name)
    nCount = 0
    for _, seVideo in genFrames.dfVideos.iterrows():
        sVideoName = seVideo.sFrameDir.split("/")[-1]
        sLabel = seVideo.sLabel
        sFeaturePath = sFeatureBaseDir + "/" + sLabel + "/" + sVideoName + ".npy"
        if os.path.exists(sFeaturePath):
            print("Video %5d: features already extracted to %s" % (nCount, sFeaturePath))
            nCount += 1
            continue
        arX, _ = genFrames.data_generation(seVideo)
        arFeature = keModel.predict(arX, verbose=0)
        os.makedirs(sFeatureBaseDir + "/" + sLabel, exist_ok = True)
        np.save(sFeaturePath, arFeature)
        print("Video %5d: features %s saved to %s" % (nCount, str(arFeature.shape), sFeaturePath))
        nCount += 1
    print("%d features saved to files in %s" % (nCount+1, sFeatureBaseDir))
    return
def features_2D_predict_generator ( sFrameBaseDir : str , sFeatureBaseDir : str , keModel : keras . Model , nFramesNorm : int = 40 ) : _ , h , w , c = keModel . input_shape genFrames = FramesGenerator ( sFrameBaseDir , 1 , nFramesNorm , h , w , c , liClassesFull = None , bShuffle = False ) print ( "Predict features with %s ... " % keModel . name ) nCount = 0 for _ , seVideo in genFrames . dfVideos . iterrows ( ) : sVideoName = seVideo . sFrameDir . split ( "/" ) [ - 1 ] sLabel = seVideo . sLabel sFeaturePath = sFeatureBaseDir + "/" + sLabel + "/" + sVideoName + ".npy" if os . path . exists ( sFeaturePath ) : print ( "Video %5d: features already extracted to %s" % ( nCount , sFeaturePath ) ) nCount += 1 continue arX , _ = genFrames . data_generation ( seVideo ) arFeature = keModel . predict ( arX , verbose = 0 ) os . makedirs ( sFeatureBaseDir + "/" + sLabel , exist_ok = True ) np . save ( sFeaturePath , arFeature ) print ( "Video %5d: features %s saved to %s" % ( nCount , str ( arFeature . shape ) , sFeaturePath ) ) nCount += 1 print ( "%d features saved to files in %s" % ( nCount + 1 , sFeatureBaseDir ) ) return
Used by the MobileNet-LSTM NN architecture.
Used by the MobileNet - LSTM NN architecture .
"""
    Used by the MobileNet-LSTM NN architecture.
    The (video) frames (2-dimensional) in sFrameBaseDir are fed into keModel (eg MobileNet without top layers)
    and the resulting features are save to sFeatureBaseDir.
    """ # do not (partially) overwrite existing feature directory #if os.path.exists(sFeatureBaseDir):  #    warnings.warn("\nFeature folder " + sFeatureBaseDir + " alredy exists, calculation stopped")  #    return # prepare frame generator - without shuffling! # Predict - loop through all samples # ... sFrameBaseDir / class / videoname=frame-directory # check if already predicted # get normalized frames and predict feature # save to file
sFrameBaseDir
str
sFeatureBaseDir
str
keModel
keras.Model
nFramesNorm
int