Skip to content

Commit 7bf5a17

Browse files
committed
python3 compat and training songs pkl
1 parent 45f245f commit 7bf5a17

File tree

8 files changed

+32
-16
lines changed

8 files changed

+32
-16
lines changed

__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from lab1 import *
2-
from lab2 import *
1+
from .lab1 import *
2+
from .lab2 import *
33
# from lab3 import *
44

55

@@ -88,7 +88,7 @@ def __init__(self, sec, xlabel='', ylabel='', scale=None):
8888
def plot(self, data):
8989
if time.time() - self.tic > self.sec:
9090
plt.cla()
91-
91+
9292
if self.scale is None:
9393
plt.plot(data)
9494
elif self.scale == 'semilogx':

lab1/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from util import *
1+
from .util import *

lab1/data/training_songs.pkl

201 KB
Binary file not shown.

lab1/util.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import os
22
import subprocess
33
import regex as re
4+
import urllib
45

6+
DATA_URL = 'https://raw.githubusercontent.com/aamini/introtodeeplearning_labs/2019/lab1/data/irish.abc'
57

6-
def extract_song_snippet(generated_text):
8+
def load_training_data():
9+
stream = urllib.request.urlopen(DATA_URL)
10+
text = stream.read().decode("utf-8")
11+
songs = extract_song_snippet(text)
12+
return songs
13+
14+
def extract_song_snippet(text):
715
pattern = '\n\n(.*?)\n\n'
8-
search_results = re.findall(pattern, generated_text, overlapped=True, flags=re.DOTALL)
16+
search_results = re.findall(pattern, text, overlapped=True, flags=re.DOTALL)
917
songs = [song for song in search_results]
10-
print "Found {} possible songs in generated texts".format(len(songs))
18+
print("Found {} songs in text".format(len(songs)))
1119
return songs
1220

1321
def save_song_to_abc(song, filename="tmp"):
@@ -25,14 +33,19 @@ def play_wav(wav_file):
2533
from IPython.display import Audio
2634
return Audio(wav_file)
2735

36+
def play_song(song):
37+
basename = save_song_to_abc(song)
38+
ret = abc2wav(basename+'.abc')
39+
if ret == 0: #did not suceed
40+
return play_wav(basename+'.wav')
41+
return None
42+
2843
def play_generated_song(generated_text):
2944
songs = extract_song_snippet(generated_text)
3045
if len(songs) == 0:
31-
print "No valid songs found in generated text. Try training the model longer or increasing the amount of generated music to ensure complete songs are generated!"
46+
print("No valid songs found in generated text. Try training the model longer or increasing the amount of generated music to ensure complete songs are generated!")
3247

48+
import pdb; pdb.set_trace()
3349
for song in songs:
34-
basename = save_song_to_abc(song)
35-
ret = abc2wav(basename+'.abc')
36-
if ret == 0: #did not suceed
37-
return play_wav(basename+'.wav')
38-
print "None of the songs were valid, try training longer to improve syntax."
50+
play_song(song)
51+
print("None of the songs were valid, try training longer to improve syntax.")

lab2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from util import *
1+
from .util import *

lab2/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
class TrainingDatasetLoader(object):
1414
def __init__(self, data_path):
1515

16-
print "Opening {}".format(data_path)
16+
print ("Opening {}".format(data_path))
1717
sys.stdout.flush()
1818

1919
self.cache = h5py.File(data_path, 'r')
2020

21-
print "Loading data into memory..."
21+
print ("Loading data into memory...")
2222
sys.stdout.flush()
2323
self.images = self.cache['images'][:]
2424
self.labels = self.cache['labels'][:]

mitdeeplearning/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import mitdeeplearning.lab1

mitdeeplearning/lab1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def func():
2+
print("hi")

0 commit comments

Comments
 (0)