def __init__(
        self,
        *,
        detection_threshold: float = 0.3,
        nms_threshold: float = 0.6,
        anchors=OPENIMAGES_ANCHORS,
        model_image_width: int = DEFAULT_MODEL_IMAGE_WIDTH,
        model_image_height: int = DEFAULT_MODEL_IMAGE_HEIGHT,
        path_to_model: str = None,
        path_to_classes: str = None,
        log_device_placement: bool = True,
        gpu_allow_growth: bool = True,
        verbose: bool = True,
    ):

        config = tf.ConfigProto()

        # dynamically grow the memory used on the GPU
        config.gpu_options.allow_growth = gpu_allow_growth

        # log device placement (on which device the operation ran)
        config.log_device_placement = log_device_placement

        # create and set this TensorFlow session as the default session for Keras
        sess = tf.Session(config=config)
        set_session(sess)

        self.session = K.get_session()

        self.model = restore_model(
        ) if path_to_model is None else restore_model(path_to_model)
        self.class_index_to_human_readable_class = load_classes(
        ) if path_to_classes is None else load_classes(path_to_classes)

        self.detection_threshold = detection_threshold
        self.nms_threshold = nms_threshold
        self.model_image_width = model_image_width
        self.model_image_height = model_image_height

        self.anchors = anchors / np.array(
            [model_image_width, model_image_height])
        out_tensors, input_tensors = _construct_out_tensors(
            restored_model=self.model,
            num_of_anchors=3,
            anchors=self.anchors,
            model_image_width=model_image_width,
            model_image_height=model_image_height,
        )

        self.out_tensors = out_tensors
        self.input_tensors = input_tensors
        self.verbose = verbose
示例#2
0
from dataset import data_gen
from matplotlib import pyplot as plt
import utils

#from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.callbacks import TensorBoard

from tensorflow.keras.callbacks import ModelCheckpoint
from tensorflow.keras.callbacks import CSVLogger
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.optimizers import Adam
from metrics.miou import MeanIoU
from keras import backend as K

import tensorflow.keras.backend.tensorflow_backend as ktf
"""
def get_session(gpu_fraction=0.333):
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction,
                                allow_growth=True)
    return tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))


ktf.set_session(get_session())
"""

flags = tf.compat.v1.app.flags
FLAGS = flags.FLAGS

flags.DEFINE_integer('batch_size', 8,
                     'The number of images in each batch during training.')
        '''
		返回tensorflow.keras model
		'''
        return self._model


if (__name__ == '__main__'):

    import tensorflow as tf
    from tensorflow.keras.backend.tensorflow_backend import set_session
    os.environ["CUDA_VISIBLE_DEVICES"] = "0"
    #进行配置,使用70%的GPU
    config = tf.ConfigProto()
    config.gpu_options.per_process_gpu_memory_fraction = 0.93
    #config.gpu_options.allow_growth=True   #不全部占满显存, 按需分配
    set_session(tf.Session(config=config))

    datapath = ''
    modelpath = 'model_speech'

    if (not os.path.exists(modelpath)):  # 判断保存模型的目录是否存在
        os.makedirs(modelpath)  # 如果不存在,就新建一个,避免之后保存模型的时候炸掉

    system_type = plat.system()  # 由于不同的系统的文件路径表示不一样,需要进行判断
    if (system_type == 'Windows'):
        datapath = 'E:\\语音数据集'
        modelpath = modelpath + '\\'
    elif (system_type == 'Linux'):
        datapath = 'dataset'
        modelpath = modelpath + '/'
    else:
示例#4
0
# BlobEnv end----------------------------------------------

env = BlobEnv()

# For stats
ep_rewards = [-200]

# For more repetitive results
random.seed(1)
np.random.seed(1)
tf.random.set_seed(1)

# Memory fraction, used mostly when trai8ning multiple agents
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=MEMORY_FRACTION)
backend.set_session(tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)))

# Create models folder
if not os.path.isdir('models'):
    os.makedirs('models')

# Own Tensorboard class------------------------------------


class ModifiedTensorBoard(TensorBoard):

    # Overriding init to set initial step and writer (we want one log file for all .fit() calls)
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.step = 1
        self.writer = tf.summary.create_file_writer(self.log_dir)