如何从类似输入字符串的列表中获取名称?

时间:2018-01-20 08:59:05

标签: python python-3.x tensorflow

我有一个如下列表

[<tf.Variable 'resnet_v1_101/conv1/weights:0' shape=(7, 7, 3, 64) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/conv1/BatchNorm/beta:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/conv1/BatchNorm/gamma:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/conv1/BatchNorm/moving_mean:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/conv1/BatchNorm/moving_variance:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/shortcut/weights:0' shape=(1, 1, 64, 256) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/shortcut/BatchNorm/beta:0' shape=(256,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/shortcut/BatchNorm/gamma:0' shape=(256,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/shortcut/BatchNorm/moving_mean:0' shape=(256,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/shortcut/BatchNorm/moving_variance:0' shape=(256,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/weights:0' shape=(1, 1, 64, 64) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/BatchNorm/beta:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/BatchNorm/gamma:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/BatchNorm/moving_mean:0' shape=(64,) dtype=float32_ref>, <tf.Variable 'resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/BatchNorm/moving_variance:0' shape=(64,) dtype=float32_ref>]

我希望在列表中获取存储BatchNorm的所有名称,并将其存储在新列表中,而不会重复。该名称将被删除,直到BatchNorm。例如 输入

'resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/BatchNorm/moving_mean

输出

'resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/BatchNorm'

我在新名单中的预期是

['resnet_v1_101/conv1/BatchNorm','resnet_v1_101/block1/unit_1/bottleneck_v1/shortcut/BatchNorm','resnet_v1_101/block1/unit_1/bottleneck_v1/conv1/BatchNorm']

0 个答案:

没有答案