MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST_F

Function TEST_F

tensorflow/core/grappler/grappler_item_builder_test.cc:38–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36class GrapplerItemBuilderTest : public ::testing::Test {};
37
38TEST_F(GrapplerItemBuilderTest, AssetFilepathOverrideTest) {
39 MetaGraphDef meta_graph;
40
41 tensorflow::Scope s = tensorflow::Scope::NewRootScope();
42 Output var =
43 ops::Variable(s.WithOpName("var"), TensorShape(), DataType::DT_FLOAT);
44 Output filename_node =
45 ops::Const(s.WithOpName("filename"), string("model"), TensorShape());
46 Output tensor_name =
47 ops::Const(s.WithOpName("tensorname"), string("var"), TensorShape());
48 Output restore = ops::Restore(s.WithOpName("restore"), filename_node,
49 tensor_name, DataType::DT_FLOAT);
50 Output assign = ops::Assign(s.WithOpName("assign"), var, restore);
51
52 TF_CHECK_OK(s.ToGraphDef(meta_graph.mutable_graph_def()));
53
54 string temp_dir = testing::TmpDir();
55
56 Env *env = Env::Default();
57 string filename =
58 io::JoinPath(temp_dir, "grappler_item_builder_test_filename");
59 env->DeleteFile(filename).IgnoreError();
60 std::unique_ptr<WritableFile> file_to_write;
61 TF_CHECK_OK(env->NewWritableFile(filename, &file_to_write));
62 TF_CHECK_OK(file_to_write->Close());
63 TF_CHECK_OK(env->FileExists(filename));
64 LOG(INFO) << filename;
65
66 AssetFileDef asset_file_def;
67 *asset_file_def.mutable_tensor_info()->mutable_name() = "filename";
68 *asset_file_def.mutable_filename() = "grappler_item_builder_test_filename";
69
70 (*meta_graph.mutable_collection_def())["saved_model_assets"]
71 .mutable_any_list()
72 ->add_value()
73 ->PackFrom(asset_file_def);
74 *((*meta_graph.mutable_collection_def())["train_op"]
75 .mutable_node_list()
76 ->add_value()) = "assign";
77
78 ItemConfig cfg;
79 cfg.assets_directory_override = temp_dir;
80
81 std::unique_ptr<GrapplerItem> item =
82 GrapplerItemFromMetaGraphDef("0", meta_graph, cfg);
83 ASSERT_TRUE(item != nullptr);
84 for (const NodeDef &node : item->graph.node()) {
85 if (node.name() == "filename") {
86 const auto iter = node.attr().find("value");
87 ASSERT_TRUE(iter != node.attr().end());
88 ASSERT_TRUE(iter->second.has_tensor());
89 ASSERT_EQ(1, iter->second.tensor().string_val_size());
90
91 string tensor_string_val = iter->second.tensor().string_val(0);
92 EXPECT_EQ(tensor_string_val, filename);
93 }
94 }
95}

Callers

nothing calls this directly

Calls 15

RestoreFunction · 0.85
TmpDirFunction · 0.85
DefaultFunction · 0.85
GDefFunction · 0.85
NDefFunction · 0.85
XTimesTwoFunction · 0.85
ItemConfigClass · 0.85
PartialTensorShapeClass · 0.85
WithOpNameMethod · 0.80
attrMethod · 0.80
mutable_inputsMethod · 0.80

Tested by

no test coverage detected