2016-11-12 1 views
0

tensorflow를 사용하여 첫 번째 다중 -gpu 모델을 교육하고 있습니다. 튜토리얼에 따르면 변수는 name_scope를 사용하여 모든 GPU에서 CPU와 연산에 고정되어 있습니다.Tensorflow : Multigpu 교육에서 CPU로 변수 고정이 작동하지 않습니다.

작은 테스트를 실행하고 장치 배치를 기록 할 때 TOWER_1/TOWER_0 접두사가있는 각 GPU에 ops가 배치되어 있지만 변수가 CPU에 배치되지 않은 것을 볼 수 있습니다.

나는 뭔가가 없거나 장치 배치 로그를 잘못 이해하고 있습니다.

device placement log

감사

테스트 코드

with tf.device('cpu:0'): 
    imgPath=tf.placeholder(tf.string) 
    imageString=tf.read_file(imgPath) 
    imageJpeg=tf.image.decode_jpeg(imageString, channels=3) 
    inputImage=tf.image.resize_images(imageJpeg, [299,299]) 
    inputs = tf.expand_dims(inputImage, 0) 
    for i in range(2): 
     with tf.device('/gpu:%d' % i): 
      with tf.name_scope('%s_%d' % ('TOWER', i)) as scope: 
       with slim.arg_scope([tf.contrib.framework.python.ops.variables.variable], device='/cpu:0'): 
        with slim.arg_scope(inception_v3.inception_v3_arg_scope()): 
         logits,endpoints = inception_v3.inception_v3(inputs, num_classes=1001, is_training=False) 
       tf.get_variable_scope().reuse_variables() 

with tf.Session(config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True)) as sess: 
    tf.initialize_all_variables().run() 
exit(0) 

편집 기본적으로 slim.arg_scope으로 라인 '([tf.contrib는 여기 테스트 코드를 부착하고 .framework.python.ops.variables.variable], device = '/ cpu : 0') : '는 cpu의 모든 변수를 강제해야하지만 create

with slim.arg_scope([slim.model_variable, slim.variable], device='/cpu:0'): 

이가에서 찍은 :에 D 'GPU : 0'으로

+0

글쎄, 당신이 요청에 따라 expand_dims'가 cpu''에 배치됩니다 '까지 변수 '와 함께 tf.device ('cpu : 0') :'. 'inception' 모델에 연결된 모든 변수는'gpu'에 저장됩니다. – sygi

+0

덕분에, slim.arg_scope ([tf.contrib.framework.python.ops.variables.variable], device = '/ cpu : 0')의 역할은 무엇입니까, 이해합니다 : '비록 –

+0

이 아닙니다. 'allow_soft_placement'가 방해 받고 있습니까? 'False'로 설정하면, 당신이 말한 곳 (또는 실패한 곳)에 배치해야합니다. – drpng

답변

관련 문제