The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

477794 (4) [Avatar] Offline
#1

Hello,

I just tried [Concept01_clustering] but got the following error.
Anyone can help on this?

By the way, I added
 sess.run(tf.local_variables_initializer()) 
before
sess.run(tf.global_variables_initializer())
to avoid [FailedPreconditionError] as shown in this article: https://forums.manning.com/posts/list/40966.page


Loading ./audio_dataset/cough_2.wav
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.CancelledError'>, Enqueue operation was cancelled
	 [[Node: input_producer/input_producer_EnqueueMany = QueueEnqueueManyV2[Tcomponents=[DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](input_producer, input_producer/RandomShuffle)]]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-7e705f0c84ef> in <module>()
      2     sess.run(tf.local_variables_initializer())
      3     sess.run(tf.global_variables_initializer())
----> 4     X, names = get_dataset(sess)
      5     centroids = initial_cluster_centroids(X, k)
      6     i, converged = 0, False

<ipython-input-15-8acacf67bdb7> in get_dataset(sess)
      8     for _ in range(num_files):
      9         plt.figure()
---> 10         chromo_data, filename = get_next_chromogram(sess)
     11 
     12         plt.subplot(1, 2, 1)

<ipython-input-13-73c48f59ba77> in get_next_chromogram(sess)
      2     audio_file = sess.run(filename)
      3     print('Loading {}'.format(audio_file))
----> 4     F = Chromagram(audio_file, nfft=16384, wfft=8192, nhop=2205)
      5     return F.X, audio_file

/home/bukim/anaconda3/envs/mltf2/lib/python2.7/site-packages/bregman/features.pyc in __init__(self, arg, **feature_params)
    141     def __init__(self, arg=None, **feature_params):
    142         feature_params['feature']='chroma'
--> 143         Features.__init__(self, arg, feature_params)
    144 
    145 class HighQuefrencyChromagram(Features):

/home/bukim/anaconda3/envs/mltf2/lib/python2.7/site-packages/bregman/features_base.pyc in __init__(self, arg, feature_params)
     68             if arg:
     69                 self.load_audio(arg) # open file as MONO signal
---> 70                 self.extract()
     71 
     72     def _initialize(self, feature_params):

/home/bukim/anaconda3/envs/mltf2/lib/python2.7/site-packages/bregman/features_base.pyc in extract(self, feature_params)
    211         """
    212         f = self._check_feature_params(feature_params)['feature']
--> 213         self.extract_funs.get(f, self._extract_error)()
    214         if self.onsets: self._extract_onsets()
    215 

/home/bukim/anaconda3/envs/mltf2/lib/python2.7/site-packages/bregman/features_base.pyc in _chroma(self)
    709         lo = self.lo
    710         self.lo = 63.5444 # set to quarter tone below C
--> 711         if not self._cqft():
    712             return False
    713         self.lo = lo # restore original lo edge

/home/bukim/anaconda3/envs/mltf2/lib/python2.7/site-packages/bregman/features_base.pyc in _cqft(self)
    586             self._cqft_intensified()
    587         else:
--> 588             self._make_log_freq_map()
    589             self.CQFT=P.sqrt(P.array(P.mat(self.Q)*P.mat(P.absolute(self.STFT)**2)))
    590             self._is_intensified=False

/home/bukim/anaconda3/envs/mltf2/lib/python2.7/site-packages/bregman/features_base.pyc in _make_log_freq_map(self)
    351         self._outN = float(self.nfft/2+1)
    352         if self._cqtN<1: print "warning: cqtN not positive definite"
--> 353         mxnorm = P.empty(self._cqtN) # Normalization coefficients
    354         fftfrqs = self._fftfrqs #P.array([i * self.sample_rate / float(self._fftN) for i in P.arange(self._outN)])
    355         logfrqs=P.array([lo_edge * P.exp(P.log(2.0)*i/bpo) for i in P.arange(self._cqtN)])

TypeError: 'float' object cannot be interpreted as an index
477794 (4) [Avatar] Offline
#2

I just got some hints from this article: https://stackoverflow.com/questions/46700885/python-typeerror-float-object-cannot-be-interpreted-as-an-index?rq=1

In fact, the error comes from Chromagram(...) in bregman package.

According to the article, Python 2 allows float used as index.
But the strange thing is that now I am using Python 2.7 and still have the same problem.

How I can fix the problem?
206159 (3) [Avatar] Offline
#3
The easy fix is to replace self._cqtN with int(self._cqtN) in the places it occurs in ...bregman/features_base.py