Example #1
0
 def CPC_feature_function(x):
     CPC_features = buildFeature(featureMaker,
                                 x,
                                 seqNorm=args.seq_norm,
                                 strict=args.strict,
                                 maxSizeSeq=args.max_size_seq)
     return CPC_features.squeeze(0).float().cpu().numpy()
Example #2
0
 def cpc_feature_function(x):
     if args.nobatch is False:
         return buildFeature_batch(featureMaker,
                                   x,
                                   seqNorm=False,
                                   strict=args.strict,
                                   maxSizeSeq=args.max_size_seq,
                                   batch_size=args.batch_size)
     else:
         return buildFeature(featureMaker,
                             x,
                             seqNorm=False,
                             strict=args.strict)
 def feature_function(x): 
     if args.nobatch is False:
         res0 = buildFeature_batch(featureMaker, x,
                                                 seqNorm=False,
                                                 strict=args.strict,
                                                 maxSizeSeq=args.max_size_seq,
                                                 batch_size=args.batch_size)
         if args.norm_vec_len:
             # [!] we actually used CPC_audio/scripts/quantize_audio.py for that in the end
             res0Lengths = torch.sqrt((res0*res0).sum(2))
             res0 = res0 / res0Lengths.view(*(res0Lengths.shape), 1)
         return res0
     else:
         res0 = buildFeature(featureMaker, x,
                             seqNorm=False,
                             strict=args.strict)
         if args.norm_vec_len:
             # [!] we actually used CPC_audio/scripts/quantize_audio.py for that in the end
             res0Lengths = torch.sqrt((res0*res0).sum(2))
             res0 = res0 / res0Lengths.view(*(res0Lengths.shape), 1)
         return res0
Example #4
0
 def cpc_feature_function(x):
     if args.nobatch is False:
         res0 = buildFeature_batch(featureMaker,
                                   x,
                                   seqNorm=False,
                                   strict=args.strict,
                                   maxSizeSeq=args.max_size_seq,
                                   batch_size=args.batch_size)
         if args.norm_vec_len:
             res0Lengths = torch.sqrt((res0 * res0).sum(2))
             res0 = res0 / res0Lengths.view(*(res0Lengths.shape), 1)
         return res0
     else:
         res0 = buildFeature(featureMaker,
                             x,
                             seqNorm=False,
                             strict=args.strict)
         if args.norm_vec_len:
             res0Lengths = torch.sqrt((res0 * res0).sum(2))
             res0 = res0 / res0Lengths.view(*(res0Lengths.shape), 1)
         return res0
Example #5
0
     def feature_function(x): return buildFeature(feature_maker, x,
                                                  seqNorm=args.seq_norm,
                                                  strict=args.strict,
                                                  maxSizeSeq=args.max_size_seq)
 elif args.load == 'from_pre_computed':
def buildAllFeature(featureMaker,
                    pathDB,
                    pathOut,
                    seqList,
                    stepSize=0.01,
                    strict=False,
                    maxSizeSeq=64000,
                    format='fea',
                    seqNorm=False):

    totSeqs = len(seqList)
    startStep = stepSize / 2
    bar = progressbar.ProgressBar(maxval=totSeqs)
    bar.start()
    for nseq, seqPath in enumerate(seqList):
        bar.update(nseq)
        feature = buildFeature(featureMaker,
                               os.path.join(pathDB, seqPath),
                               strict=strict or seqNorm,
                               maxSizeSeq=maxSizeSeq,
                               seqNorm=seqNorm)

        _, nSteps, hiddenSize = feature.size()
        outName = os.path.basename(os.path.splitext(seqPath)[0]) + f'.{format}'
        fname = os.path.join(pathOut, outName)

        if format == 'npz':
            time = [startStep + step * stepSize for step in range(nSteps)]
            values = feature.squeeze(0).float().cpu().numpy()
            totTime = np.array([stepSize * nSteps], dtype=np.float32)
            with open(fname, 'wb') as f:
                np.savez(f, time=time, features=values, totTime=totTime)
        elif format == 'npy':
            time = [startStep + step * stepSize for step in range(nSteps)]
            values = feature.squeeze(0).float().cpu().numpy()
            with open(fname, 'wb') as f:
                np.save(f, values)
        elif format == 'af':
            import arrayfire as af
            time = [startStep + step * stepSize for step in range(nSteps)]
            values = feature.squeeze(0).float().cpu().numpy()
            totTime = np.array([stepSize * nSteps], dtype=np.float32)
            af.save_array("time", af.Array(time, dtype=af.Dtype.f32), fname)
            af.save_array("totTime",
                          af.interop.from_ndarray(totTime),
                          fname,
                          append=True)
            af.save_array("features",
                          af.interop.from_ndarray(values),
                          fname,
                          append=True)
        else:
            with open(fname, 'w') as f:
                _, nSteps, hiddenSize = feature.size()
                for step in range(nSteps):
                    line = [startStep + step * stepSize] + \
                        feature[0, step, :].tolist()
                    line = [str(x) for x in line]
                    linestr = ' '.join(line) + '\n'
                    f.write(linestr)
    bar.finish()
Example #7
0
 def feature_function(x):
     return buildFeature(feature_maker,
                         x,
                         seqNorm=args.seq_norm,
                         strict=args.strict,
                         maxSizeSeq=args.max_size_seq)