Skip to content

Commit

Permalink
python3 compat and training songs pkl
Browse files Browse the repository at this point in the history
  • Loading branch information
aamini committed Dec 31, 2019
1 parent 45f245f commit 7bf5a17
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 16 deletions.
6 changes: 3 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from lab1 import *
from lab2 import *
from .lab1 import *
from .lab2 import *
# from lab3 import *


Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self, sec, xlabel='', ylabel='', scale=None):
def plot(self, data):
if time.time() - self.tic > self.sec:
plt.cla()

if self.scale is None:
plt.plot(data)
elif self.scale == 'semilogx':
Expand Down
2 changes: 1 addition & 1 deletion lab1/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from util import *
from .util import *
Binary file added lab1/data/training_songs.pkl
Binary file not shown.
31 changes: 22 additions & 9 deletions lab1/util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import os
import subprocess
import regex as re
import urllib

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

def extract_song_snippet(generated_text):
def load_training_data():
stream = urllib.request.urlopen(DATA_URL)
text = stream.read().decode("utf-8")
songs = extract_song_snippet(text)
return songs

def extract_song_snippet(text):
pattern = '\n\n(.*?)\n\n'
search_results = re.findall(pattern, generated_text, overlapped=True, flags=re.DOTALL)
search_results = re.findall(pattern, text, overlapped=True, flags=re.DOTALL)
songs = [song for song in search_results]
print "Found {} possible songs in generated texts".format(len(songs))
print("Found {} songs in text".format(len(songs)))
return songs

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

def play_song(song):
basename = save_song_to_abc(song)
ret = abc2wav(basename+'.abc')
if ret == 0: #did not suceed
return play_wav(basename+'.wav')
return None

def play_generated_song(generated_text):
songs = extract_song_snippet(generated_text)
if len(songs) == 0:
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!"
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!")

import pdb; pdb.set_trace()
for song in songs:
basename = save_song_to_abc(song)
ret = abc2wav(basename+'.abc')
if ret == 0: #did not suceed
return play_wav(basename+'.wav')
print "None of the songs were valid, try training longer to improve syntax."
play_song(song)
print("None of the songs were valid, try training longer to improve syntax.")
2 changes: 1 addition & 1 deletion lab2/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from util import *
from .util import *
4 changes: 2 additions & 2 deletions lab2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
class TrainingDatasetLoader(object):
def __init__(self, data_path):

print "Opening {}".format(data_path)
print ("Opening {}".format(data_path))
sys.stdout.flush()

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

print "Loading data into memory..."
print ("Loading data into memory...")
sys.stdout.flush()
self.images = self.cache['images'][:]
self.labels = self.cache['labels'][:]
Expand Down
1 change: 1 addition & 0 deletions mitdeeplearning/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import mitdeeplearning.lab1
2 changes: 2 additions & 0 deletions mitdeeplearning/lab1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def func():
print("hi")

0 comments on commit 7bf5a17

Please sign in to comment.