| 168 | return initializer_op |
| 169 | |
| 170 | def add_global_constant( |
| 171 | self, name, array=None, dtype=None, initializer=None |
| 172 | ): |
| 173 | assert isinstance(name, str), ( |
| 174 | 'name should be a string as we are using it as map key') |
| 175 | # This is global namescope for constants. They will be created in all |
| 176 | # init_nets and there should be very few of them. |
| 177 | assert name not in self.global_constants, \ |
| 178 | "%s already added in global_constants" % name |
| 179 | blob_name = self.net.NextBlob(name) |
| 180 | self.global_constants[name] = blob_name |
| 181 | initializer_op = LayerModelHelper._get_global_constant_initializer_op( |
| 182 | blob_name, array, dtype, initializer |
| 183 | ) |
| 184 | assert blob_name not in self.global_constant_initializers, \ |
| 185 | "there is already a initializer op associated with blob %s" % \ |
| 186 | blob_name |
| 187 | self.global_constant_initializers[blob_name] = initializer_op |
| 188 | return blob_name |
| 189 | |
| 190 | def maybe_add_global_constant(self, name, *args, **kwargs): |
| 191 | # To ad hoc add new global constants without duplication |