def set_watched(self, id):
     for item in [item for item in self._items if item['id']==id and item['playcount']==0]:
         item['playcount'] = 1
         item['lastplayed'] = helper.current_time()
         self.update(['Suggested', 'Recent', 'Random'] if self.__randomUpdateMethod else ['Suggested', 'Recent'])
 def start_playing(self, id):
     for item in [item for item in self._items if item['id']==id]:
         item['lastplayed'] = helper.current_time()
Ejemplo n.º 3
0
def train_nn(sess, epochs, batch_size, get_batches_fn, train_op, loss,
             predictions, input_image, correct_label, keep_prob, learning_rate,
             saver):
    """
    Train neural network and print out the loss during training.
    :param sess: TF Session
    :param epochs: Number of epochs
    :param batch_size: Batch size
    :param get_batches_fn: Function to get batches of training data.  Call using get_batches_fn(batch_size)
    :param train_op: TF Operation to train the neural network
    :param cross_entropy_loss: TF Tensor for the amount of loss
    :param input_image: TF Placeholder for input images
    :param correct_label: TF Placeholder for label images
    :param keep_prob: TF Placeholder for dropout keep probability
    :param learning_rate: TF Placeholder for learning rate
    """

    #     max_loss = 10000
    for epoch_i in range(1, epochs + 1):
        epoch_loss = 0
        steps = 1
        for images, labels in get_batches_fn(batch_size):
            _, batch_loss = sess.run(
                [train_op, loss],
                feed_dict={
                    input_image: images,
                    correct_label: labels,
                    keep_prob: 0.75,
                    learning_rate: 0.0001
                })
            epoch_loss += batch_loss
        mean_epoch_loss = epoch_loss * 1.0 / steps
        # print every Epoch
        print(
            "Epoch {}/{} \t".format(epoch_i, epochs),
            "Epoch Loss: {:.4f}  Last Batch Loss: {:.4f}".format(
                mean_epoch_loss, batch_loss))
        steps += 1

        # every 10 epochs, run on mini_test images, save test images with mask
        if epoch_i % 10 == 0:
            mean_iou = helper.save_inference_samples(runs_dir,
                                                     data_dir,
                                                     sess,
                                                     image_shape,
                                                     predictions,
                                                     keep_prob,
                                                     input_image,
                                                     epoch=epoch_i,
                                                     mini=True,
                                                     compute_iou=True)
            print("Epoch{} iou:{} ".format(epoch_i, mean_iou))

        # save last 3 model
        if epoch_i > (epochs - 3):
            save_path = saver.save(
                sess,
                "./models/models-{}-{}-{}/segmentation_model.ckpt".format(
                    epoch_i, mean_epoch_loss, current_time()))
        # TODO:val_loss is decreasing, save model

    # use last model test on whole testset
    final_modeliou = helper.save_inference_samples(runs_dir,
                                                   data_dir,
                                                   sess,
                                                   image_shape,
                                                   predictions,
                                                   keep_prob,
                                                   input_image,
                                                   epoch=epoch_i,
                                                   mini=False,
                                                   compute_iou=True)
    print("Final Model iou: ", final_mean_iou)