Exemplo n.º 1
0
iteration = 15000
batch_size = 1000


file_name='warehouse'
fileObject = open(file_name,'rb')  
years = pickle.load(fileObject)
timbres = pickle.load(fileObject)
pitches = pickle.load(fileObject)
min_length = pickle.load(fileObject)
non_time_features = pickle.load(fileObject)
fileObject.close()

#train_timbres,cv_timbres,test_timbres = songProcess.dataset_split(timbres)
#train_pitches,cv_pitches,test_pitches = songProcess.dataset_split(pitches)
train_non_time,cv_non_time,test_non_time = songProcess.dataset_split(non_time_features)
train_year,cv_year,test_year = songProcess.dataset_split(years)

#sklearn-begin
'''
cv_array = np.arange(0, len(cv_year))
cv_X_without_year,cv_y = songProcess.get_batch_non_time_data(cv_array,cv_non_time,cv_year)
cv_y = songProcess.transfer_year_to_decade(cv_y)

index_array = np.arange(0, np.size(train_year)) 
batch_X_without_year,batch_y = songProcess.get_batch_non_time_data(index_array,train_non_time,train_year)
batch_y_10d = songProcess.transfer_year_to_10d(songProcess.transfer_year_to_decade(batch_y))

scaler = MinMaxScaler(feature_range=(-5,5))
scaler.fit(batch_X_without_year)
batch_X_without_year = scaler.transform(batch_X_without_year)
Exemplo n.º 2
0
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

iteration = 10000
batch_size = 256

file_name = 'warehouse'
fileObject = open(file_name, 'rb')
years = pickle.load(fileObject)
timbres = pickle.load(fileObject)
pitches = pickle.load(fileObject)
min_length = pickle.load(fileObject)
non_time_features = pickle.load(fileObject)
fileObject.close()

train_timbres, cv_timbres, test_timbres = songProcess.dataset_split(timbres)
train_pitches, cv_pitches, test_pitches = songProcess.dataset_split(pitches)
train_non_time, cv_non_time, test_non_time = songProcess.dataset_split(
    non_time_features)
train_year, cv_year, test_year = songProcess.dataset_split(years)


def add_layer(inputs, in_size, out_size, activation_function=None):
    Weights = tf.Variable(tf.random_normal([in_size, out_size]))
    biases = tf.Variable(tf.zeros([1, out_size]) + 0.1)
    Wx_plus_b = tf.matmul(inputs, Weights) + biases
    if activation_function is None:
        outputs = Wx_plus_b
    else:
        outputs = activation_function(Wx_plus_b)
    return outputs
batch_size = 64

'''Data processing'''
#read data
file_name='warehouse'
fileObject = open(file_name,'rb')  
years = pickle.load(fileObject)
timbres = pickle.load(fileObject)
pitches = pickle.load(fileObject)
min_length = pickle.load(fileObject)
fileObject.close()
total_size = len(years)

'''Data Spliting'''
#training set
train_timbres,cv_timbres,test_timbres = songProcess.dataset_split(timbres)
train_pitches,cv_pitches,test_pitches = songProcess.dataset_split(pitches)
train_years,cv_years,test_years = songProcess.dataset_split(years)
cv_array = np.arange(0, len(cv_years))
cv_X, cv_y = songProcess.get_batch_data(cv_array, min_length, cv_timbres, cv_pitches, cv_years)

'''RNN Model Definition'''
# tensorflow placeholders
tf_x = tf.placeholder(tf.float32, [None, min_length * INPUT_SIZE])       # shape(batch, 784)   [time_steps, batch_size, num_features]
image = tf.reshape(tf_x, [-1, INPUT_SIZE,min_length])                   # (batch, height, width, channel)
tf_y = tf.placeholder(tf.int32, [None, 10])                             # input y

# RNN
rnn_cell = tf.contrib.rnn.BasicLSTMCell(
    num_units=300,
    forget_bias=0.8,