musdb/__init__.py
def test(self, user_function):
        """Test the musdb user_function output

        Parameters
        ----------
        user_function : callable, optional
            function which separates the mixture into estimates.

        Raises
        ------
        TypeError
            If the provided function handle is not callable.

        ValueError
            If the output is not compliant to the bsseval methods

        See Also
        --------
        run : Process the musdb
        """
        if not hasattr(user_function, '__call__'):
            raise TypeError("Please provide a function.")

        test_track = Track(name="test - test")
        signal = np.random.random((66000, 2))
        test_track.audio = signal
        test_track.rate = 44100
        test_track.subset = 'test'

        sources = {}
        for src, source_file in list(
            self.setup['sources'].items()
        ):
            source = Source(name=src)
            source.audio = signal
            source.rate = test_track.rate
            sources[src] = source
        test_track.sources = sources

        # add targets to track
        targets = collections.OrderedDict()
        for name, target_srcs in list(
            self.setup['targets'].items()
        ):
            # add a list of target sources
            target_sources = []
            for source, gain in list(target_srcs.items()):
                if source in list(test_track.sources.keys()):
                    # add gain to source tracks
                    test_track.sources[source].gain = float(gain)
                    # add tracks to components
                    target_sources.append(sources[source])
            # add sources to target
            if target_sources:
                targets[name] = Target(sources=target_sources)

        # add targets to track
        test_track.targets = targets

        user_results = user_function(test_track)

        if isinstance(user_results, dict):
            for target, audio in list(user_results.items()):
                if target not in self.targets_names:
                    raise ValueError("Target '%s' not supported!" % target)

                d = audio.dtype
                if not (
                    np.issubdtype(d, np.float32) or
                    np.issubdtype(d, np.float64)
                ):
                    raise ValueError(
                        "Estimate is not of type numpy.float32 or float64"
                    )

                if audio.shape != signal.shape:
                    raise ValueError(
                        "Shape of estimate does not match input shape"
                    )

        else:
            raise ValueError("output needs to be a dict")

        return True
Test the musdb user_function output

        Parameters
        ----------
        user_function : callable, optional
            function which separates the mixture into estimates.

        Raises
        ------
        TypeError
            If the provided function handle is not callable.

        ValueError
            If the output is not compliant to the bsseval methods

        See Also
        --------
        run : Process the musdb
        
Test the musdb user_function output
Parameters

user_function : callable, optional
function which separates the mixture into estimates.

Raises

TypeError
If the provided function handle is not callable.

ValueError
If the output is not compliant to the bsseval methods

See Also

run : Process the musdb
Test the musdb user_function output Parameters user_function : callable optional function which separates the mixture into estimates . Raises TypeError If the provided function handle is not callable . ValueError If the output is not compliant to the bsseval methods See Also run : Process the musdb
def test(self, user_function):
        if not hasattr(user_function, '__call__'):
            raise TypeError("Please provide a function.")
        test_track = Track(name="test - test")
        signal = np.random.random((66000, 2))
        test_track.audio = signal
        test_track.rate = 44100
        test_track.subset = 'test'
        sources = {}
        for src, source_file in list(
            self.setup['sources'].items()
        ):
            source = Source(name=src)
            source.audio = signal
            source.rate = test_track.rate
            sources[src] = source
        test_track.sources = sources
        targets = collections.OrderedDict()
        for name, target_srcs in list(
            self.setup['targets'].items()
        ):
            target_sources = []
            for source, gain in list(target_srcs.items()):
                if source in list(test_track.sources.keys()):
                    test_track.sources[source].gain = float(gain)
                    target_sources.append(sources[source])
            if target_sources:
                targets[name] = Target(sources=target_sources)
        test_track.targets = targets
        user_results = user_function(test_track)
        if isinstance(user_results, dict):
            for target, audio in list(user_results.items()):
                if target not in self.targets_names:
                    raise ValueError("Target '%s' not supported!" % target)
                d = audio.dtype
                if not (
                    np.issubdtype(d, np.float32) or
                    np.issubdtype(d, np.float64)
                ):
                    raise ValueError(
                        "Estimate is not of type numpy.float32 or float64"
                    )
                if audio.shape != signal.shape:
                    raise ValueError(
                        "Shape of estimate does not match input shape"
                    )
        else:
            raise ValueError("output needs to be a dict")
        return True
def test ( self , user_function ) : if not hasattr ( user_function , '__call__' ) : raise TypeError ( "Please provide a function." ) test_track = Track ( name = "test - test" ) signal = np . random . random ( ( 66000 , 2 ) ) test_track . audio = signal test_track . rate = 44100 test_track . subset = 'test' sources = { } for src , source_file in list ( self . setup [ 'sources' ] . items ( ) ) : source = Source ( name = src ) source . audio = signal source . rate = test_track . rate sources [ src ] = source test_track . sources = sources targets = collections . OrderedDict ( ) for name , target_srcs in list ( self . setup [ 'targets' ] . items ( ) ) : target_sources = [ ] for source , gain in list ( target_srcs . items ( ) ) : if source in list ( test_track . sources . keys ( ) ) : test_track . sources [ source ] . gain = float ( gain ) target_sources . append ( sources [ source ] ) if target_sources : targets [ name ] = Target ( sources = target_sources ) test_track . targets = targets user_results = user_function ( test_track ) if isinstance ( user_results , dict ) : for target , audio in list ( user_results . items ( ) ) : if target not in self . targets_names : raise ValueError ( "Target '%s' not supported!" % target ) d = audio . dtype if not ( np . issubdtype ( d , np . float32 ) or np . issubdtype ( d , np . float64 ) ) : raise ValueError ( "Estimate is not of type numpy.float32 or float64" ) if audio . shape != signal . shape : raise ValueError ( "Shape of estimate does not match input shape" ) else : raise ValueError ( "output needs to be a dict" ) return True
Test the musdb user_function output
Parameters
Test the musdb user_function output Parameters
"""Test the musdb user_function output

        Parameters
        ----------
        user_function : callable, optional
            function which separates the mixture into estimates.

        Raises
        ------
        TypeError
            If the provided function handle is not callable.

        ValueError
            If the output is not compliant to the bsseval methods

        See Also
        --------
        run : Process the musdb
        """ # add targets to track # add a list of target sources # add gain to source tracks # add tracks to components # add sources to target # add targets to track
self
user_function