资源简介

基于深度学习开发的自主避障算法

资源截图

代码片段和文件信息

import tensorflow as tf
import numpy as np
import os
import sys
import gflags

from keras.callbacks import ModelCheckpoint
from keras import optimizers

import logz
import cnn_models
import utils
import log_utils
from common_flags import FLAGS



def getModel(img_width img_height img_channels output_dim weights_path):
    “““
    Initialize model.

    # Arguments
       img_width: Target image widht.
       img_height: Target image height.
       img_channels: Target image channels.
       output_dim: Dimension of model output.
       weights_path: Path to pre-trained model.

    # Returns
       model: A Model instance.
    “““
    model = cnn_models.resnet8(img_width img_height img_channels output_dim)

    if weights_path:
        try:
            model.load_weights(weights_path)
            print(“Loaded model from {}“.format(weights_path))
        except:
            print(“Impossible to find weight path. Returning untrained model“)

    return model


def trainModel(train_data_generator val_data_generator model initial_epoch):
    “““
    Model training.

    # Arguments
       train_data_generator: Training data generated batch by batch.
       val_data_generator: Validation data generated batch by batch.
       model: Target image channels.
       initial_epoch: Dimension of model output.
    “““

    # Initialize loss weights
    model.alpha = tf.Variable(1 trainable=False name=‘alpha‘ dtype=tf.float32)
    model.beta = tf.Variable(0 trainable=False name=‘beta‘ dtype=tf.float32)

    # Initialize number of samples for hard-mining
    model.k_mse = tf.Variable(FLAGS.batch_size trainable=False name=‘k_mse‘ dtype=tf.int32)
    model.k_entropy = tf.Variable(FLAGS.batch_size trainable=False name=‘k_entropy‘ dtype=tf.int32)


    optimizer = optimizers.Adam(decay=1e-5)

    # Configure training process
    model.compile(loss=[utils.hard_mining_mse(model.k_mse)
                        utils.hard_mining_entropy(model.k_entropy)]
                        optimizer=optimizer loss_weights=[model.alpha model.beta])

    # Save model with the lowest validation loss
    weights_path = os.path.join(FLAGS.experiment_rootdir ‘weights_{epoch:03d}.h5‘)
    writeBestModel = ModelCheckpoint(filepath=weights_path monitor=‘val_loss‘
                                     save_best_only=True save_weights_only=True)

    # Save model every ‘log_rate‘ epochs.
    # Save training and validation losses.
    logz.configure_output_dir(FLAGS.experiment_rootdir)
    saveModelAndLoss = log_utils.MyCallback(filepath=FLAGS.experiment_rootdir
                                            period=FLAGS.log_rate
                                            batch_size=FLAGS.batch_size)

    # Train model
    steps_per_epoch = int(np.ceil(train_data_generator.samples / FLAGS.batch_size))
    validation_steps = int(np.ceil(val_data_generator.samples / FLAGS.batch_size))

    model.fit_generator(train_data_generator
                        epochs=FLAGS

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件     1610372  2019-03-20 15:41  Dronet.pdf
     文件     2077111  2019-03-20 15:26  RAL18_Loquercio.pdf
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\
     文件        6455  2018-05-24 17:59  rpg_public_dronet-master\cnn.py
     文件        3043  2018-05-24 17:59  rpg_public_dronet-master\cnn_models.py
     文件        1645  2018-05-24 17:59  rpg_public_dronet-master\common_flags.py
     文件          31  2018-05-24 17:59  rpg_public_dronet-master\constants.py
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\data_preprocessing\
     文件        2012  2018-05-24 17:59  rpg_public_dronet-master\data_preprocessing\time_stamp_matching.py
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\configs\
     文件        1228  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\configs\outdoor.yaml
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\
     文件         191  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\CMakeLists.txt
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\include\
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\include\dronet_control\
     文件        1960  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\include\dronet_control\deep_navigation.h
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\launch\
     文件         507  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\launch\deep_navigation.launch
     文件         533  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\package.xml
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\src\
     文件        3619  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_control\src\deep_navigation.cpp
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\
     文件           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\__init__.py
     文件         466  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\CMakeLists.txt
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\launch\
     文件        1066  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\launch\bebop_launch.launch
     文件         856  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\launch\dronet_launch.launch
     文件        1881  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\launch\full_perception_launch.launch
     目录           0  2018-05-24 17:59  rpg_public_dronet-master\drone_control\dronet\dronet_perception\models\
............此处省略29个文件信息

评论

共有 条评论