1. 按比例
1 config = tf.ConfigProto() 2 config.gpu_options.per_process_gpu_memory_fraction = 0.4 3 session = tf.Session(config=config, ...)
or
1 session_bundle_config.mutable_session_config() 2 ->mutable_gpu_options() 3 ->set_per_process_gpu_memory_fraction(0.4);
2.按需求增长
1 config = tf.ConfigProto() 2 config.gpu_options.allow_growth = True 3 session = tf.Session(config=config, ...)
or
1 session_bundle_config.mutable_session_config() 2 ->mutable_gpu_options() 3 ->set_allow_growth(true);