Skip to content

Commit

Permalink
Merge pull request #53 from JohnVinyard/python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
JohnVinyard committed Mar 7, 2019
2 parents 7a75d80 + fce685d commit d5df840
Show file tree
Hide file tree
Showing 155 changed files with 589 additions and 569 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python
python:
# We don't actually use the Travis Python, but this keeps it organized.
- "2.7"
- "3.6"
before_install:
- chmod +x setup.sh
- sudo ./setup.sh
Expand All @@ -21,7 +21,7 @@ install:
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
- conda create -q -n test-environment -c pytorch -c hcc -c conda-forge python=$TRAVIS_PYTHON_VERSION numpy=1.15.3 scipy=1.1.0 cython pytorch=0.4 torchvision libsndfile=1.0.28 libsamplerate=0.1.8 libflac=1.3.1 libogg=1.3.2
- conda create -q -n test-environment -c pytorch -c hcc -c conda-forge python=$TRAVIS_PYTHON_VERSION numpy=1.15.3 scipy=1.2.1 cython pytorch=0.4 torchvision libsndfile=1.0.28 libsamplerate=0.1.8 libflac=1.3.1 libogg=1.3.2
- sudo ldconfig /opt/conda/lib
- source activate test-environment
- python setup.py install
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ RUN wget http://www.mega-nerd.com/tmp/libsndfile-1.0.26pre5.tar.gz \
&& cd ..

RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh \
&& wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh \
&& /bin/bash /Miniconda-latest-Linux-x86_64.sh -b -p /opt/conda \
&& rm /Miniconda-latest-Linux-x86_64.sh
&& wget https://repo.continuum.io/miniconda/Miniconda3-4.3.21-Linux-x86_64.sh \
&& /bin/bash /Miniconda3-4.3.21-Linux-x86_64.sh -b -p /opt/conda \
&& rm /Miniconda3-4.3.21-Linux-x86_64.sh

ENV PATH /opt/conda/bin:$PATH

RUN conda install -y -c pytorch numpy=1.15.3 scipy=1.1.0 pytorch=0.4
RUN conda install -y -c pytorch numpy=1.15.3 scipy=1.2.1 pytorch=0.4

RUN pip install zounds

Expand Down
14 changes: 7 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
master_doc = 'index'

# General information about the project.
project = u'zounds'
copyright = u'2017, John Vinyard'
author = u'John Vinyard'
project = 'zounds'
copyright = '2017, John Vinyard'
author = 'John Vinyard'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -232,8 +232,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'zounds.tex', u'zounds Documentation',
u'John Vinyard', 'manual'),
(master_doc, 'zounds.tex', 'zounds Documentation',
'John Vinyard', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -262,7 +262,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'zounds', u'zounds Documentation',
(master_doc, 'zounds', 'zounds Documentation',
[author], 1)
]

Expand All @@ -276,7 +276,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'zounds', u'zounds Documentation',
(master_doc, 'zounds', 'zounds Documentation',
author, 'zounds', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
8 changes: 4 additions & 4 deletions examples/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class Sound(BaseModel):
def samples(x):
return zounds.AudioSamples(x, sr)

batch_slow = map(samples, time_stretch(windowed, 0.75))
batch_fast = map(samples, time_stretch(windowed, 1.25))
batch_slow = list(map(samples, time_stretch(windowed, 0.75)))
batch_fast = list(map(samples, time_stretch(windowed, 1.25)))

batch_higher = map(samples, pitch_shift(windowed, 1.0))
batch_lower = map(samples, pitch_shift(windowed, -1.0))
batch_higher = list(map(samples, pitch_shift(windowed, 1.0)))
batch_lower = list(map(samples, pitch_shift(windowed, -1.0)))

app = zounds.ZoundsApp(
model=Sound,
Expand Down
2 changes: 1 addition & 1 deletion examples/erb_mdct.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
makes inversion easier, at the cost of more redundancy.
"""

from __future__ import division

import zounds
import scipy

Expand Down
4 changes: 2 additions & 2 deletions examples/freesound.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Sound(BaseModel):
url = request.url
if not Sound.exists(url):
Sound.process(meta=metadata, _id=url)
print 'processed {url}'.format(**locals())
print('processed {url}'.format(**locals()))
else:
print 'already processed {url}'.format(**locals())
print('already processed {url}'.format(**locals()))

snds = list(Sound)

Expand Down
2 changes: 1 addition & 1 deletion examples/hamming_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def total_duration(doc, ts):
if not len(index):
index.add_all()

for i in xrange(1000):
for i in range(1000):
list(index.random_search(n_results=50, sort=True))


10 changes: 5 additions & 5 deletions examples/mdct_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,21 @@ class DctKmeansWithLogAmplitude(ff.BaseModel):
# https://archive.org/details/FlavioGaete
# - https://archive.org/download/FlavioGaete/FlavioGaete22.zip
filename = 'FlavioGaete22.zip'
print 'Processing Audio...'
print('Processing Audio...')
for zf in ff.iter_zip(filename):
if '._' in zf.filename:
continue
try:
# check if the feature already exists
Document(zf.filename).mdct.shape
except KeyError:
print 'processing {filename}'.format(filename=zf.filename)
print('processing {filename}'.format(filename=zf.filename))
Document.process(meta=zf, _id=zf.filename)

print 'learn k-means clusters'
print('learn k-means clusters')
DctKmeans.process(docs=(doc.mdct for doc in Document))

print 'learn k-means clusters with log amplitude'
print('learn k-means clusters with log amplitude')
DctKmeansWithLogAmplitude.process(docs=(doc.mdct for doc in Document))

synth = zounds.MDCTSynthesizer()
Expand Down Expand Up @@ -167,7 +167,7 @@ def reconstruction(_id=None):
doc = Document(_id)
else:
doc = choice(docs)
print doc._id
print(doc._id)
recon_audio = full_pass(doc.mdct, kmeans.pipeline)
recon_audio_log_amp = full_pass(doc.mdct, kmeans_log_amplitude.pipeline)
return doc.ogg[:], recon_audio, recon_audio_log_amp
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch_autoencoder_raw_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def forward(self, input, target):
# instantiate the trained pipeline
pipeline = pipeline_cls()

snds = filter(lambda snd: args.internet_archive_id in snd._id, Sound)
snds = [snd for snd in Sound if args.internet_archive_id in snd._id]
snd = choice(snds)
time_slice = zounds.TimeSlice(duration=zounds.Seconds(10))
encoded = pipeline.pipeline.transform(
Expand Down
37 changes: 19 additions & 18 deletions examples/pytorch_wgan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division

import numpy as np
import featureflow as ff
import zounds
Expand All @@ -14,6 +14,7 @@
from random import choice
import torch.nn.functional as F
from uuid import uuid4
from functools import reduce

samplerate = zounds.SR11025()
BaseModel = zounds.resampled(resample_to=samplerate, store_resampled=True)
Expand Down Expand Up @@ -146,11 +147,11 @@ def __init__(self):

self.feature_map_sizes = reduce(
lambda x, y: x + [int(x[-1] * FACTOR)],
xrange(len(bands) - 1),
range(len(bands) - 1),
[FIRST_FEATURE_MAP_SIZE])

for i, band in enumerate(bands):
for j in xrange(i + 1):
for j in range(i + 1):
fms = self.feature_map_sizes[j]
first_layer = j == 0
in_channels = 1 if first_layer else self.feature_map_sizes[
Expand Down Expand Up @@ -194,11 +195,11 @@ def __init__(self):
self.factor = FACTOR
self.feature_map_sizes = reduce(
lambda x, y: x + [int(x[-1] * FACTOR)],
xrange(len(bands) - 1),
range(len(bands) - 1),
[FIRST_FEATURE_MAP_SIZE])

for i, band in enumerate(bands):
for j in xrange(i + 1):
for j in range(i + 1):
fms = self.feature_map_sizes[j]
first_layer = j == 0
out_channels = 1 if first_layer else self.feature_map_sizes[
Expand Down Expand Up @@ -309,10 +310,10 @@ def try_network():
c = network.discriminator

result = g(v, debug=True)
print result.size()
print(result.size())

labels = c(result, debug=True)
print labels.size()
print(labels.size())


@zounds.simple_settings
Expand Down Expand Up @@ -395,7 +396,7 @@ def load_and_play():
glob.glob('*.npy'),
cmp=lambda x, y: int(os.stat(x).st_ctime - os.stat(y).st_ctime))
most_recent = files[-1]
print 'loading generated examples from', most_recent
print('loading generated examples from', most_recent)
results = np.load(most_recent)

# synthesized = FrequencyDecomposition.synthesize_block(results)
Expand All @@ -410,11 +411,11 @@ def load_and_play():


def synthetic():
for i in xrange(100):
for i in range(100):
duration = zounds.Seconds(np.random.randint(2, 20))
root = np.random.randint(50, 400)
hz = [root]
for _ in xrange(0):
for _ in range(0):
hz.append(hz[-1] * 2)
synth = zounds.SineSynthesizer(samplerate)
s = synth.synthesize(duration, hz)
Expand Down Expand Up @@ -453,7 +454,7 @@ def arg_maker(epoch):
v = Variable(t).cuda()
samples = network.generator(v).data.cpu().numpy().squeeze()
np.save('epoch' + str(epoch), samples)
print 'saved samples for epoch', epoch
print('saved samples for epoch', epoch)
return dict()

# out_channels = 128
Expand Down Expand Up @@ -500,7 +501,7 @@ def arg_maker(epoch):
p = Gan()

def walk2(steps):
for i in xrange(steps):
for i in range(steps):
yield np.random.normal(0, 1, LATENT_DIM)

def listen():
Expand Down Expand Up @@ -529,7 +530,7 @@ def test_frequency_decomposition():
inp = Variable(inp).cuda()
x = gen(inp)

print x.size()
print(x.size())

disc = FDDiscriminator().cuda()

Expand All @@ -540,10 +541,10 @@ def test_frequency_decomposition():
# inp = Variable(inp).cuda()

x = disc(x)
print x.size()
print(x.size())

print gen.layers
print disc.layers
print(gen.layers)
print(disc.layers)


def tweak():
Expand Down Expand Up @@ -578,8 +579,8 @@ def get_magnitudes():
m = np.abs(b).mean()
magnitudes.append(m)
scaled.append(np.abs(b / m).mean())
print magnitudes
print scaled
print(magnitudes)
print(scaled)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/richard_nixon_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def generate_training_and_test_set():
snds = list(Sound)

# get all sounds where Nixon is the speaker
nixon = filter(lambda snd: 'Nixon' in snd.meta['artist'], snds)
nixon = [snd for snd in snds if 'Nixon' in snd.meta['artist']]

# get an equal number of speeches by anyone besides Nixon
not_nixon = filter(
Expand Down
4 changes: 2 additions & 2 deletions examples/segmentsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ class WithCodes(WithOnsets):

# learn K-Means centroids from the drum hits
if not BarkKmeans.exists():
print 'learning K-Means clusters'
print('learning K-Means clusters')
BarkKmeans.process(docs=(wo.bark for wo in WithOnsets))

# bark_kmeans = BarkKmeans()

# force the new pooled feature to be computed
for doc in WithCodes:
print doc.pooled.slicedata.shape
print(doc.pooled.slicedata.shape)

results = index.random_search(n_results=5)

Expand Down
14 changes: 7 additions & 7 deletions examples/timbre.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from urlparse import urlparse
from urllib.parse import urlparse
import featureflow as ff
import requests
import zounds
Expand Down Expand Up @@ -85,7 +85,7 @@ def download_zip_archive():
if not os.path.exists(filename):
resp = requests.get(url, stream=True)

print 'Downloading {url} -> {filename}...'.format(**locals())
print('Downloading {url} -> {filename}...'.format(**locals()))

with open(filename, 'wb') as f:
for chunk in resp.iter_content(chunk_size=1000000):
Expand All @@ -99,30 +99,30 @@ def download_zip_archive():

zip_filename = download_zip_archive()

print 'Processing Audio...'
print('Processing Audio...')
for zf in ff.iter_zip(zip_filename):

if '._' in zf.filename:
continue

try:
print 'processing {zf.filename}'.format(**locals())
print('processing {zf.filename}'.format(**locals()))
WithTimbre.process(
_id=zf.filename, meta=zf, raise_if_exists=True)
except ff.ModelExistsError as e:
print e
print(e)

# learn K-Means centroids
try:
print 'learning K-Means centroids'
print('learning K-Means centroids')
BfccKmeans.process(
docs=(wt.bfcc for wt in WithTimbre), raise_if_exists=True)
except ff.ModelExistsError:
pass

# force the new features to be computed, so they're pushed into the index
for wc in WithCodes:
print wc.bfcc_kmeans_pooled
print(wc.bfcc_kmeans_pooled)

app = zounds.ZoundsSearch(
model=WithTimbre,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ tornado==4.5.3
pysoundfile
matplotlib==1.5.0
numpy==1.15.3
scipy==1.1.0
scipy==1.2.1
torch==0.4.0

0 comments on commit d5df840

Please sign in to comment.