python类GPUOptions()的实例源码

train_embedding.py 文件源码 项目:youtube-8m 作者: wangheda 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __init__(self, cluster, task, train_dir, log_device_placement=True):
    """"Creates a Trainer.

    Args:
      cluster: A tf.train.ClusterSpec if the execution is distributed.
        None otherwise.
      task: A TaskSpec describing the job type and the task index.
    """

    self.cluster = cluster
    self.task = task
    self.is_master = (task.type == "master" and task.index == 0)
    self.train_dir = train_dir
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.2)
    self.config = tf.ConfigProto(log_device_placement=log_device_placement,gpu_options=gpu_options)

    if self.is_master and self.task.index > 0:
      raise StandardError("%s: Only one replica of master expected",
                          task_as_string(self.task))
train.py 文件源码 项目:youtube-8m 作者: wangheda 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self, cluster, task, train_dir, log_device_placement=True):
    """"Creates a Trainer.

    Args:
      cluster: A tf.train.ClusterSpec if the execution is distributed.
        None otherwise.
      task: A TaskSpec describing the job type and the task index.
    """

    self.cluster = cluster
    self.task = task
    self.is_master = (task.type == "master" and task.index == 0)
    self.train_dir = train_dir
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=FLAGS.gpu)
    self.config = tf.ConfigProto(log_device_placement=log_device_placement)

    if self.is_master and self.task.index > 0:
      raise StandardError("%s: Only one replica of master expected",
                          task_as_string(self.task))
wrapper.py 文件源码 项目:vae-npvc 作者: JeremyCCHsu 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def configure_gpu_settings(gpu_cfg=None):
    session_conf = None
    if gpu_cfg:
        with open(gpu_cfg) as f:
            cfg = json.load(f)
        gpu_options = tf.GPUOptions(
            per_process_gpu_memory_fraction=cfg['per_process_gpu_memory_fraction'])
        session_conf = tf.ConfigProto(
            allow_soft_placement=cfg['allow_soft_placement'],
            log_device_placement=cfg['log_device_placement'],
            inter_op_parallelism_threads=cfg['inter_op_parallelism_threads'],
            intra_op_parallelism_threads=cfg['intra_op_parallelism_threads'],
            gpu_options=gpu_options)
        # Timeline
        # jit_level = 0
        # session_conf.graph_options.optimizer_options.global_jit_level = jit_level
    #     sess = tf.Session(
    #         config=session_conf)
    # else:
    #     sess = tf.Session()
    return session_conf
test_dbinterface.py 文件源码 项目:tfutils 作者: neuroailab 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def setUp(self):
        """Set up class before _each_ test method is executed.

        Creates a tensorflow session and instantiates a dbinterface.

        """
        self.setup_model()
        self.sess = tf.Session(
            config=tf.ConfigProto(
                allow_soft_placement=True,
                gpu_options=tf.GPUOptions(allow_growth=True),
                log_device_placement=self.params['log_device_placement'],
                inter_op_parallelism_threads=self.params['inter_op_parallelism_threads']))

        # TODO: Determine whether this should be called here or
        # in dbinterface.initialize()
        self.sess.run(tf.global_variables_initializer())

        self.dbinterface = base.DBInterface(sess=self.sess,
                                            params=self.params,
                                            cache_dir=self.CACHE_DIR,
                                            save_params=self.save_params,
                                            load_params=self.load_params)

        self.step = 0
predict.py 文件源码 项目:tensorflow_seq2seq_chatbot 作者: higepon 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def predict():
    # Only allocate part of the gpu memory when predicting.
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.2)
    tf_config = tf.ConfigProto(gpu_options=gpu_options)

    with tf.Session(config=tf_config) as sess:

        predictor = EasyPredictor(sess)

        sys.stdout.write("> ")
        sys.stdout.flush()
        line = sys.stdin.readline()
        while line:
            replies = predictor.predict(line)
            for i, text in enumerate(replies):
                print(i, text)
            print("> ", end="")
            sys.stdout.flush()
            line = sys.stdin.readline()
distributed_sit.py 文件源码 项目:GoogleCloudSetup 作者: tmulc18 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def main():
    # Graph
    with tf.device('/cpu:0'):
        a = tf.Variable(tf.truncated_normal(shape=[2]),dtype=tf.float32)
        b = tf.Variable(tf.truncated_normal(shape=[2]),dtype=tf.float32)
        c=a+b

        target = tf.constant(100.,shape=[2],dtype=tf.float32)
        loss = tf.reduce_mean(tf.square(c-target))

        opt = tf.train.GradientDescentOptimizer(.0001).minimize(loss)

    # Session
    #sv = tf.train.Supervisor(logdir='/tmp/mydir')
    sv = tf.train.Supervisor(logdir='/tmp/mydir')
    gpu_options = tf.GPUOptions(allow_growth=True,allocator_type="BFC",visible_device_list="%d"%FLAGS.gpu_id)
    config = tf.ConfigProto(gpu_options=gpu_options,allow_soft_placement=False,device_count={'GPU':1},log_device_placement=True)
    sess = sv.prepare_or_wait_for_session(config=config)
    for i in range(1000):
        sess.run(opt)
        if i % 10 == 0:
            r = sess.run(c)
            print(r)
        time.sleep(.1)
main.py 文件源码 项目:RFR-solution 作者: baoblackcoal 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def main(_):
  gpu_options = tf.GPUOptions(
      per_process_gpu_memory_fraction=calc_gpu_fraction(FLAGS.gpu_fraction))

  with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:
    config = get_config(FLAGS) or FLAGS

    if config.env_type == 'simple':
      env = SimpleGymEnvironment(config)
    else:
      env = GymEnvironment(config)

    if not tf.test.is_gpu_available() and FLAGS.use_gpu:
      raise Exception("use_gpu flag is true when no GPUs are available")

    if not FLAGS.use_gpu:
      config.cnn_format = 'NHWC'

    agent = Agent(config, env, sess)

    if FLAGS.is_train:
      agent.train()
    else:
      agent.play()
run_dqn_atari.py 文件源码 项目:rl_algorithms 作者: DanielTakeshi 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_session():
    tf.reset_default_graph()
    tf_config = tf.ConfigProto(
        inter_op_parallelism_threads=1,
        intra_op_parallelism_threads=1)

    # This was the default provided in the starter code.
    #session = tf.Session(config=tf_config)

    # Use this if I want to see what is on the GPU.
    #session = tf.Session(config=tf.ConfigProto(log_device_placement=True))

    # Use this for limiting memory allocated for the GPU.
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
    session = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

    print("AVAILABLE GPUS: ", get_available_gpus())
    return session
process.py 文件源码 项目:DocumentSegmentation 作者: SeguinBe 项目源码 文件源码 阅读 59 收藏 0 点赞 0 评论 0
def process(input_dir, output_dir, model_dir, resizing_size, gpu):
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3, visible_device_list=gpu)
    with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)).as_default():
        m = loader.LoadedModel(model_dir)

    os.makedirs(output_dir, exist_ok=True)

    input_filenames = glob(os.path.join(input_dir, '*.jpg')) + \
                      glob(os.path.join(input_dir, '*.png')) + \
                      glob(os.path.join(input_dir, '*.tif')) + \
                      glob(os.path.join(input_dir, '*.jp2'))

    for path in tqdm(input_filenames):
        img = Image.open(path).resize(resizing_size)
        mat = np.asarray(img)
        if len(mat.shape) == 2:
            mat = np.stack([mat, mat, mat], axis=2)
        predictions = m.predict(mat[None], prediction_key='labels')[0]
        plt.imsave(os.path.join(output_dir, os.path.relpath(path, input_dir)), predictions)
test.py 文件源码 项目:Deep-Image-Matting 作者: Joker316701882 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def main(args):

    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction = args.gpu_fraction)
    with tf.Session(config=tf.ConfigProto(gpu_options = gpu_options)) as sess:
        saver = tf.train.import_meta_graph('./meta_graph/my-model.meta')
        saver.restore(sess,tf.train.latest_checkpoint('./model'))
        image_batch = tf.get_collection('image_batch')[0]
        GT_trimap = tf.get_collection('GT_trimap')[0]
        pred_mattes = tf.get_collection('pred_mattes')[0]

        rgb = misc.imread(args.rgb)
        alpha = misc.imread(args.alpha,'L')
        trimap = generate_trimap(np.expand_dims(np.copy(alpha),2),np.expand_dims(alpha,2))[:,:,0]
        origin_shape = alpha.shape
        rgb = np.expand_dims(misc.imresize(rgb.astype(np.uint8),[320,320,3]).astype(np.float32)-g_mean,0)
        trimap = np.expand_dims(np.expand_dims(misc.imresize(trimap.astype(np.uint8),[320,320],interp = 'nearest').astype(np.float32),2),0)

        feed_dict = {image_batch:rgb,GT_trimap:trimap}
        pred_alpha = sess.run(pred_mattes,feed_dict = feed_dict)
        final_alpha = misc.imresize(np.squeeze(pred_alpha),origin_shape)
        # misc.imshow(final_alpha)
        misc.imsave('./alpha.png',final_alpha)
main.py 文件源码 项目:rnnprop 作者: vfleaking 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def main(argv):
    pprint.pprint(tf.app.flags.FLAGS.__flags)

    flags = tf.app.flags.FLAGS        

    graph = tf.Graph()
    os.environ["CUDA_VISIBLE_DEVICES"]=str(flags.gpu)
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.22, allow_growth=True)
    with graph.as_default():
        with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options),graph=graph) as session:
            all_tests = test_list.tests
            tasks = task_list.tasks

            if flags.train == 'optimizer':
                train_optimizer(tasks[flags.task])
            elif flags.train == 'optimizee':
                train_optimizee(all_tests[flags.task])
            elif flags.train == 'optimizer_train_optimizee':
                optimizer_train_optimizee(tasks[flags.task])
            elif flags.train == 'test':
                test(tasks[flags.task])
save_weights.py 文件源码 项目:tf_face 作者: ZhijianChan 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def main(args):
    if args.meta_file == None or not os.path.exists(args.meta_file):
        print("Invalid tensorflow meta-graph file:", args.meta_file)
        return

    gpu_options = tf.GPUOptions(allow_growth=True)
    sess = tf.Session(config=tf.ConfigProto(
        gpu_options=gpu_options,
        log_device_placement=False,
        allow_soft_placement=True))
    with sess.as_default():
        # ---- load pretrained parameters ---- #
        saver = tf.train.import_meta_graph(args.meta_file, clear_devices=True)
        saver.restore(tf.get_default_session(), args.ckpt_file)
        pretrained = {}
        var_ = tf.get_collection(tf.GraphKeys.MODEL_VARIABLES)
        print("total:", len(var_))
        for v in var_:
            print("process:", v.name)
            # [notice: the name of parameter is like 'Resnet/conv2d/bias:0',
            #  here we should remove the prefix name, and get '/conv2d/bias:0']
            v_name = v.name
            pretrained[v_name] = sess.run([v])
    np.save(args.save_path, pretrained)
    print("done:", len(pretrained.keys()))
predict.py 文件源码 项目:Seq2Seq-chatbot 作者: wataruhashimoto52 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def predict():
    tf_config = tf.ConfigProto(gpu_options = tf.GPUOptions(visible_device_list = "0"))
    with tf.Session(config=tf_config) as sess:

        predictor = EasyPredictor(sess)
        sys.stdout.write("> ")
        sys.stdout.flush()
        line = sys.stdin.readline()
        while line:
            replies = predictor.predict(line)
            #for i, text in enumerate(replies):
                #print(i, text)
            print(replies[0])
            print("> ", end = "")
            sys.stdout.flush()
            line = sys.stdin.readline()
main.py 文件源码 项目:miccai17-mmwhs-hybrid 作者: xy0806 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def main(_):
    # load training parameter #
    ini_file = '../outcome/model/ini/tr_param.ini'
    param_sets = load_train_ini(ini_file)
    param_set = param_sets[0]

    print '====== Phase >>> %s <<< ======' % param_set['phase']

    if not os.path.exists(param_set['chkpoint_dir']):
        os.makedirs(param_set['chkpoint_dir'])
    if not os.path.exists(param_set['labeling_dir']):
        os.makedirs(param_set['labeling_dir'])

    # GPU setting, per_process_gpu_memory_fraction means 95% GPU MEM ,allow_growth means unfixed memory
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.95, allow_growth=True)
    with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, allow_soft_placement=True)) as sess:
        model = unet_3D_xy(sess, param_set)

        if param_set['phase'] == 'train':
            model.train()
        elif param_set['phase'] == 'test':
            # model.test()
            model.test_generate_map()
        elif param_set['phase'] == 'crsv':
            model.test4crsv()
agent_base.py 文件源码 项目:trpo 作者: jjkke88 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, env):
        self.env = env
        # if not isinstance(env.observation_space, Box) or \
        #    not isinstance(env.action_space, Discrete):
        #     print("Incompatible spaces.")
        #     exit(-1)
        print("Observation Space", env.observation_space)
        print("Action Space", env.action_space)
        print("Action area, high:%f, low%f" % (env.action_space.high, env.action_space.low))
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.1 / 3.0)
        self.session = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        self.end_count = 0
        self.paths = []
        self.train = True
        self.baseline = Baseline()
        self.storage = Storage(self, self.env, self.baseline)
        self.distribution = DiagonalGaussian(pms.action_shape)
        self.net = None

    # def init_logger(self):
    #     head = ["average_episode_std" , "sum steps episode number" "total number of episodes" ,
    #             "Average sum of rewards per episode" ,
    #             "KL between old and new distribution" , "Surrogate loss" , "Surrogate loss prev" , "ds" , "entropy" ,
    #             "mean_advant"]
    #     self.logger = Logger(head)
main.py 文件源码 项目:slither.ml 作者: MadcowD 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def main(_):
  gpu_options = tf.GPUOptions(
      per_process_gpu_memory_fraction=calc_gpu_fraction(FLAGS.gpu_fraction))

  with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:
    config = get_config(FLAGS) or FLAGS
    env = UniverseEnvironment(config)

    if not tf.test.is_gpu_available() and FLAGS.use_gpu:
      raise Exception("use_gpu flag is true when no GPUs are available")

    if not FLAGS.use_gpu:
      config.cnn_format = 'NHWC'

    agent = Agent(config, env, sess)
    while True:
      try:
        if FLAGS.is_train:
          agent.train()
        else:
          agent.play()
      except universe.error.Error:
        print("Environment crashed, restarting.")
        agent.env= UniverseEnvironment(config)
train_estimator.py 文件源码 项目:Classification_Nets 作者: BobLiu20 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def main(_):
    # set up TF environment
    os.environ['CUDA_VISIBLE_DEVICES'] = FLAGS.gpus
    gpus_list = FLAGS.gpus.split(',')
    # save prefix
    prefix = '%s/%s/%s/%d' % (FLAGS.working_root, FLAGS.dataset_name,
                              FLAGS.model_name, FLAGS.try_num)
    if not os.path.exists(prefix):
        os.makedirs(prefix)
    # start
    model_params = {"num_classes": 10, "gpus_list": gpus_list}
    run_config = tf.estimator.RunConfig()
    run_config = run_config.replace(
        model_dir=prefix,
        log_step_count_steps=100,
        save_checkpoints_secs=600,
        session_config=tf.ConfigProto(allow_soft_placement=True,
                                      gpu_options=tf.GPUOptions(allow_growth=True)))
    nn = tf.estimator.Estimator(
        model_fn=model_fn, params=model_params, config=run_config)
    nn.train(input_fn=lambda: input_fn(
        len(gpus_list)), steps=None, max_steps=None)
train_val.py 文件源码 项目:lsdc 作者: febert 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def visualize(conf):

    conf['data_dir'] = '/'.join(str.split(conf['data_dir'], '/')[:-1] + ['test'])
    conf['visualize'] = conf['output_dir'] + '/' + FLAGS.visualize
    conf['event_log_dir'] = '/tmp'
    conf['batch_size'] = 1
    conf['train_val_split'] =1

    with tf.variable_scope('model', reuse=None) as training_scope:
        model = Model(conf)

    saver = tf.train.Saver(tf.get_collection(tf.GraphKeys.VARIABLES), max_to_keep=0)
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.9)
    sess = tf.InteractiveSession(config=tf.ConfigProto(gpu_options=gpu_options))

    sess.run(tf.initialize_all_variables())
    saver.restore(sess, conf['visualize'])

    # vis_different_goalpos(conf, model, sess)
    vis_different_ballpos(conf, model, sess)
training.py 文件源码 项目:atari-rl 作者: brendanator 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def train(self):
    self.training = True

    util.log('Creating session and loading checkpoint')
    session = tf.train.MonitoredTrainingSession(
        checkpoint_dir=self.config.run_dir,
        save_summaries_steps=0,  # Summaries will be saved with train_op only
        config=tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True)))

    with session:
      if len(self.agents) == 1:
        self.train_agent(session, self.agents[0])
      else:
        self.train_threaded(session)

    util.log('Training complete')
evaluate.py 文件源码 项目:fast-feature-fool 作者: val-iisc 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def classify(net, in_im, net_name, im_list, gt_labels):
    config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))
    imgs = open(im_list).readlines()
    gt_labels = open(gt_labels).readlines()
    fool_rate = 0
    top_1 = 0
    with tf.Session(config=config) as sess:
        sess.run(tf.global_variables_initializer())
        for i,name in enumerate(imgs):
            if net_name == 'caffenet':
                im = img_preprocess(name.strip(), size=227)
            else:
                im = img_preprocess(name.strip())
            softmax_scores = sess.run(net['prob'], feed_dict={in_im: im})
            if i!=0 and i%1000 == 0:
                print 'iter: {:5d}\ttop-1: {:04.2f}\tfooling-rate: {:04.2f}'.format(i, (top_1/float(i))*100, (fool_rate)/float(i)*100)
            if np.argmax(softmax_scores[0]) == int(gt_labels[i].strip()):
                top_1 += 1
            if np.argmax(softmax_scores[0]) != np.argmax(softmax_scores[1]):
                fool_rate += 1
    print 'Top-1 Accuracy = {:.2f}'.format(top_1/500.0)
    print 'Fooling Rate = {:.2f}'.format(fool_rate/500.0)
deepq.py 文件源码 项目:fathom 作者: rdadolf 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def setup(self, setup_options=None):
    super(DeepQ,self).setup(setup_options=setup_options)
    with self.G.as_default():
      if setup_options is None:
        self.setup_config = tf.ConfigProto(gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=self.params['gpu_fraction']))
      else:
        self.setup_config = tf.ConfigProto(**setup_options)
        self.setup_config.gpu_options.per_process_gpu_memory_fraction=self.params['gpu_fraction']

      self.sess = tf.Session(config=self.setup_config)
      self.init = tf.global_variables_initializer()
      self.sess.run(self.init)
      self.sess.run(self.cp_ops)

      self.reset_game()
      self.step = 0
      self.reset_statistics('all')
      self.train_cnt = self.sess.run(self.qnet.global_step)
caffe_model.py 文件源码 项目:face 作者: xpzouying 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def init_caffe_model(model_path):
    """Init caffe model for detect face.

    """

    print('Creating networks and loading parameters')
    print('Load models path: ', model_path)

    start = time.time()  # measure load caffe model

    with tf.Graph().as_default():
        # TODO: GUI accelerate
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=1.0)
        sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
        with sess.as_default():
            pnet, rnet, onet = detect_face.create_mtcnn(sess, model_path)
            global _pnet
            _pnet = pnet
            global _rnet
            _rnet = rnet
            global _onet
            _onet = onet

    print('time used: ', time.time()-start)
srez_main.py 文件源码 项目:Generative-Adversarial-Network 作者: K-Du 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def setup_tensorflow():
    # Create session
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=FLAGS.gpu_fraction)
    config = tf.ConfigProto(log_device_placement=FLAGS.log_device_placement, gpu_options=gpu_options)
    sess = tf.Session(config=config)

    # Initialize rng with a deterministic seed
    with sess.graph.as_default():
        tf.set_random_seed(FLAGS.random_seed)

    random.seed(FLAGS.random_seed)
    np.random.seed(FLAGS.random_seed)

    summary_writer = tf.summary.FileWriter(FLAGS.train_dir, sess.graph)

    return sess, summary_writer
config.py 文件源码 项目:odin 作者: imito 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def get_session_config():
  import tensorflow as tf
  session_args = {
      'intra_op_parallelism_threads': CONFIG['nthread'],
      'inter_op_parallelism_threads': CONFIG['ncpu'],
      'allow_soft_placement': True,
      'log_device_placement': CONFIG['debug'],
  }
  if CONFIG['ngpu'] > 0:
    if CONFIG['cnmem'] > 0:
      session_args['gpu_options'] = tf.GPUOptions(
          per_process_gpu_memory_fraction=CONFIG['cnmem'],
          allow_growth=False)
    else:
      session_args['gpu_options'] = tf.GPUOptions(
          allow_growth=True)
  return session_args
network.py 文件源码 项目:cifar10-tensorflow 作者: namakemono 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def __init__(self, image_size=24, num_classes=10, batch_size=50, channels=3):
        self._image_size = image_size
        self._num_classes = num_classes
        self._batch_size = batch_size
        self._channels = channels
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
        self._session = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        self._images = tf.placeholder(tf.float32, shape=[None, self._image_size, self._image_size, self._channels])
        self._labels = tf.placeholder(tf.int64, shape=[None])
        self._keep_prob = tf.placeholder(tf.float32)
        self._global_step = tf.Variable(0, tf.int64, name="global_step") 
        self._logits = self._inference(self._images, self._keep_prob)
        self._avg_loss = self._loss(self._labels, self._logits)
        self._train_op = self._train(self._avg_loss)
        self._accuracy = F.accuracy_score(self._labels, self._logits)
        self._saver = tf.train.Saver(tf.all_variables())
        self._session.run(tf.initialize_all_variables())
ops.py 文件源码 项目:deepsleepnet 作者: akaraspt 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def set_gpu_fraction(sess=None, gpu_fraction=0.3):
    """Set the GPU memory fraction for the application.

    Parameters
    ----------
    sess : a session instance of TensorFlow
        TensorFlow session
    gpu_fraction : a float
        Fraction of GPU memory, (0 ~ 1]

    References
    ----------
    - `TensorFlow using GPU <https://www.tensorflow.org/versions/r0.9/how_tos/using_gpu/index.html>`_
    """
    print("  tensorlayer: GPU MEM Fraction %f" % gpu_fraction)
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction)
    sess = tf.Session(config = tf.ConfigProto(gpu_options = gpu_options))
    return sess
yolo_v1.py 文件源码 项目:yolo-tensorflow 作者: persistforever 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def debug(self, processor):
        # ????
        train_class_labels, train_object_masks, train_nobject_masks, \
            train_box_labels, train_box_masks = self.process_labels_cpu(processor.train_labels)
        # ????
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.25)
        self.sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        self.sess.run(tf.global_variables_initializer())
        # ??
        [temp] = self.sess.run(
            fetches=[self.observe],
            feed_dict={self.images: numpy.random.random(size=[128, 384, 384, 3]),
                       self.labels: numpy.random.randint(low=0, high=1, size=[128, 20, 5]),
                       self.keep_prob: 1.0})
        print(temp.shape)
        self.sess.close()
yolo_v2.py 文件源码 项目:yolo-tensorflow 作者: persistforever 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def debug(self, processor):
        # ????
        train_class_labels, train_object_masks, train_nobject_masks, \
            train_box_labels, train_box_masks = self.process_labels_cpu(processor.train_labels)
        # ????
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.25)
        self.sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        self.sess.run(tf.global_variables_initializer())
        # ??
        [temp] = self.sess.run(
            fetches=[self.observe],
            feed_dict={self.images: numpy.random.random(size=[128, 384, 384, 3]),
                       self.labels: numpy.random.randint(low=0, high=1, size=[128, 20, 5]),
                       self.keep_prob: 1.0})
        print(temp.shape)
        self.sess.close()
yolo_prepare.py 文件源码 项目:yolo-tensorflow 作者: persistforever 项目源码 文件源码 阅读 95 收藏 0 点赞 0 评论 0
def debug(self, processor):
        # ????
        train_class_labels, train_object_masks, train_nobject_masks, \
            train_box_labels, train_box_masks = self.process_labels_cpu(processor.train_labels)
        # ????
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.25)
        self.sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        self.sess.run(tf.global_variables_initializer())
        # ??
        [temp] = self.sess.run(
            fetches=[self.observe],
            feed_dict={self.images: numpy.random.random(size=[128, 384, 384, 3]),
                       self.labels: numpy.random.randint(low=0, high=1, size=[128, 20, 5]),
                       self.keep_prob: 1.0})
        print(temp.shape)
        self.sess.close()
ops.py 文件源码 项目:tensorlayer-chinese 作者: shorxp 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def set_gpu_fraction(sess=None, gpu_fraction=0.3):
    """Set the GPU memory fraction for the application.

    Parameters
    ----------
    sess : a session instance of TensorFlow
        TensorFlow session
    gpu_fraction : a float
        Fraction of GPU memory, (0 ~ 1]

    References
    ----------
    - `TensorFlow using GPU <https://www.tensorflow.org/versions/r0.9/how_tos/using_gpu/index.html>`_
    """
    print("[TL]: GPU MEM Fraction %f" % gpu_fraction)
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction)
    sess = tf.Session(config = tf.ConfigProto(gpu_options = gpu_options))
    return sess


问题


面经


文章

微信
公众号

扫码关注公众号