通过修改命名空间绕过pb冲突
2019-05-04 本文已影响0人
机器学习插画师
背景
在实际工作当中,很多服务框架本身会依赖pb,但是和tf的pb会发生冲突[通常是因为pb比较老或者版本有冲突导致],所以本文介绍如何通过修改名空间的方式来绕过pb冲突。
修改名空间&编译pb
修改名空间的脚本rename_namespace.sh
grep -rl "\<google\>" ./protobuf | grep -v Binary | xargs sed -i "s/\<google\>/new_namespace/g"
grep -rl "protobuf_google_2fprotobuf_2f" ./protobuf | grep -v Binary | xargs sed -i "s/protobuf_google_2fprotobuf_2f/protobuf_new_namespace_2fprotobuf_2f/g"
sed -i "s/m\/new_namespace/m\/google/g" ./protobuf/autogen.sh
mv protobuf/python/google protobuf/python/new_namespace
mv protobuf/python/compatibility_tests/v2.5.0/tests/google protobuf/python/compatibility_tests/v2.5.0/tests/new_namespace
mv protobuf/python/compatibility_tests/v2.5.0/protos/python/google protobuf/python/compatibility_tests/v2.5.0/protos/python/new_namespace
mv protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/new_namespace
mv protobuf/src/google protobuf/src/new_namespace
mv protobuf/ruby/src/main/java/google protobuf/ruby/src/main/java/new_namespace
mv protobuf/ruby/src/main/java/com/google protobuf/ruby/src/main/java/com/new_namespace
mv protobuf/ruby/lib/google protobuf/ruby/lib/new_namespace
mv protobuf/ruby/ext/google protobuf/ruby/ext/new_namespace
mv protobuf/javanano/src/test/java/com/google protobuf/javanano/src/test/java/com/new_namespace
mv protobuf/javanano/src/main/java/com/google protobuf/javanano/src/main/java/com/new_namespace
mv protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google protobuf/csharp/compatibility_tests/v3.0.0/protos/src/new_namespace
mv protobuf/php/ext/google protobuf/php/ext/new_namespace
mv protobuf/objectivec/google protobuf/objectivec/new_namespace
mv protobuf/java/util/src/test/proto/com/google protobuf/java/util/src/test/proto/com/new_namespace
mv protobuf/java/util/src/test/java/com/google protobuf/java/util/src/test/java/com/new_namespace
mv protobuf/java/util/src/main/java/com/google protobuf/java/util/src/main/java/com/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/new_namespace
mv protobuf/java/core/src/test/proto/com/google protobuf/java/core/src/test/proto/com/new_namespace
mv protobuf/java/core/src/test/java/com/google protobuf/java/core/src/test/java/com/new_namespace
mv protobuf/java/core/src/main/java/com/google protobuf/java/core/src/main/java/com/new_namespace
修改tensorflow里面的命名空间
grep -rl "\<google\>" ./tensorflow/core | grep -v Binary | xargs sed -i "s/\<google\>/new_namespace/g"
grep -rl "\<google\>" ./tensorflow/contrib/decision_trees | grep -v Binary | xargs sed -i "s/\<google\>/new_namespace/g"