Esempio n. 1
0
    def Predict(
            self,
            model,  # can be the model itself or model path.
            spectrograms,  # spectrograms that are generated from the given track.
            output_directory=None,
            track_name=None):
        ''' this function takes a series of spectrograms and then predict them in parallel then returns a concatenated spectrograms'''

        if type(model) == str:  # if model is a path not real object.
            if not os.path.exists(model):
                print('Model does not exist')
                return None
            model = tf.keras.models.load_model(model)

        # Prediction part.----------------------------------------------
        start_time = time.time()

        manager = Pool()
        outputs = manager.go(model.predict, spectrograms)
        outputs = [outputs[i][0] for i in range(len(spectrograms))]
        full_output_stem = reduce(lambda a, b: np.concatenate([a, b], axis=0),
                                  outputs)

        prediction_time = time.time() - start_time
        print(
            f'[LOG] prediction done. Prediction time: {prediction_time:.3f} seconds'
        )

        return full_output_stem