示例#1
0
文件: net.py 项目: RDDDIB/neuromusic
def main(_):
    global TOTAL, ID_LENGTH
    if not os.path.exists(TRAIN_FILE):
        music.main()

    # Import data
    with open(TRAIN_FILE, 'r') as file:
        data = json.load(file)
        data_train = data["train"]
        data_test = data["test"]
        iddict = data["keys"]

    # Length of input
    TOTAL = len(data_train[0][0])
    # Length of output
    ID_LENGTH = len(data_train[0][1])

    # Create the model
    x = tf.placeholder(tf.float32, [None, TOTAL])

    # Define loss and optimizer
    y_ = tf.placeholder(tf.float32, [None, ID_LENGTH])

    # Build the graph for the deep net
    y_conv = deepnn(x)

    with tf.name_scope('loss'):
        cross_entropy = tf.nn.softmax_cross_entropy_with_logits(labels=y_,
                                                                logits=y_conv)
    cross_entropy = tf.reduce_mean(cross_entropy)

    with tf.name_scope('adam_optimizer'):
        train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)

    with tf.name_scope('accuracy'):
        correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))
        correct_prediction = tf.cast(correct_prediction, tf.float32)
    accuracy = tf.reduce_mean(correct_prediction)

    graph_location = tempfile.mkdtemp()
    print('Saving graph to: %s' % graph_location)
    train_writer = tf.summary.FileWriter(graph_location)
    train_writer.add_graph(tf.get_default_graph())

    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        for i in range(10000):
            inds = npr.randint(len(data_train), size=10)
            batch = [data_train[i] for i in inds]
            left = [entry[0] for entry in batch]
            right = [entry[1] for entry in batch]
            if i % 100 == 0:
                train_accuracy = accuracy.eval(feed_dict={x: left, y_: right})
                print('step %d, training accuracy %g' % (i, train_accuracy))
            train_step.run(feed_dict={x: left, y_: right})

        left = [entry[0] for entry in data_test]
        right = [entry[1] for entry in data_test]
        print('test accuracy: ', accuracy.eval(feed_dict={x: left, y_: right}))
示例#2
0
def music_recs():
    music.main()
示例#3
0
def ya_music(user_id, body, counter):
    track = music.main(body)
    if track == "YmdlWrongUrlError":
        write(user_id, "Неправильный url.")
    else:
        file_send(user_id, track, counter, music=True)
示例#4
0
def exit():
    with open('working.pcl', 'wb') as f:
        pickle.dump(finalList, f)
    f.close()
    root.destroy()
    main()
示例#5
0
def doMenuItem(current):
    #menuList = ["About", "Snake", "Flappy Bird", "Simon", "Breakout", "Music Box", "2048", "LED Fun", "Test All", Files]
    if current == 0:
        about()
    elif current == 1:
        import snake
        snake.main(gg)
        del sys.modules['snake']
        gc.collect()
        drawMenu(current)
    elif current == 2:
        import flappy
        flappy.main(gg)
        del sys.modules['flappy']
        gc.collect()
        drawMenu(2)
    elif current == 3:
        import simon
        simon.main(gg)
        del sys.modules['simon']
        gc.collect()
        drawMenu(3)
    elif current == 4:
        import AnimeBreakout
        AnimeBreakout.main(gg)
        del sys.modules['AnimeBreakout']
        gc.collect()
        drawMenu(current)
    elif current == 5:
        import music
        music.main(gg)
        del sys.modules['music']
        gc.collect()
        drawMenu(current)
    elif current == 6:
        import g2048
        g2048.main(gg)
        del sys.modules['g2048']
        gc.collect()
        drawMenu(current)
    elif current == 7:
        testLEDs()
    elif current == 8:
        testAll()
    elif current == 9:
        showFiles()
    elif current == 10:
        showOS()
    elif current == 11:
        import machine
        machine.reset()
    elif current == 12:
        utime.sleep_ms(200)
        if gg.playSound:
            menuList[12] = "Sound: Off"
            gg.playSound = False
        else:
            menuList[12] = "Sound: On"
            gg.playSound = True
            gg.beep()
            utime.sleep_ms(25)
            gg.lowBeep()
            utime.sleep_ms(25)
            gg.beep()
        utime.sleep_ms(200)
        drawMenu(current)
    gc.collect()