31
31
type = str ,
32
32
default = os .path .join (
33
33
os .path .dirname (os .path .abspath (__file__ )),
34
- "../test /data/cartpole_small" ))
34
+ "../tests /data/cartpole_small" ))
35
35
36
36
37
37
class CustomLossModel (Model ):
38
38
"""Custom model that adds an imitation loss on top of the policy loss."""
39
39
40
40
def _build_layers_v2 (self , input_dict , num_outputs , options ):
41
41
self .obs_in = input_dict ["obs" ]
42
- self .fcnet = FullyConnectedNetwork (input_dict , self .obs_space ,
43
- num_outputs , options )
42
+ with tf .variable_scope ("shared" , reuse = tf .AUTO_REUSE ):
43
+ self .fcnet = FullyConnectedNetwork (input_dict , self .obs_space ,
44
+ num_outputs , options )
44
45
return self .fcnet .outputs , self .fcnet .last_layer
45
46
46
47
def custom_loss (self , policy_loss , loss_inputs ):
@@ -49,12 +50,10 @@ def custom_loss(self, policy_loss, loss_inputs):
49
50
input_ops = reader .tf_input_ops ()
50
51
51
52
# define a secondary loss by building a graph copy with weight sharing
52
- with tf .variable_scope (
53
- self .scope , reuse = tf .AUTO_REUSE , auxiliary_name_scope = False ):
54
- logits , _ = self ._build_layers_v2 ({
55
- "obs" : restore_original_dimensions (input_ops ["obs" ],
56
- self .obs_space )
57
- }, self .num_outputs , self .options )
53
+ logits , _ = self ._build_layers_v2 ({
54
+ "obs" : restore_original_dimensions (input_ops ["obs" ],
55
+ self .obs_space )
56
+ }, self .num_outputs , self .options )
58
57
59
58
# You can also add self-supervised losses easily by referencing tensors
60
59
# created during _build_layers_v2(). For example, an autoencoder-style
0 commit comments