AI-TensorFlow-Libtensorflow

 view release on metacpan or  search on metacpan

t/upstream/CAPI/018_ImportGraphDef.t  view on Meta::CPAN


	note 'Check return operation';
	my $return_opers = $results->ReturnOperations;
	is $return_opers, array {
		item 0 => object {
			# not remapped
			call Name => $scalar2->Name;
		};
		end;
	}, 'return opers';

	undef $results;

	note 'Import again, with control dependencies, into the same graph.';
	undef $opts;
	$opts = AI::TensorFlow::Libtensorflow::ImportGraphDefOptions->New;
	$opts->SetPrefix("imported3");
	$opts->AddControlDependency($feed);
	$opts->AddControlDependency($feed2);
	$graph->ImportGraphDef($graph_def, $opts, $s);
	TF_Utils::AssertStatusOK($s);

	ok my $scalar3 = $graph->OperationByName("imported3/scalar"), "imported3/scalar";
	ok my $feed3 = $graph->OperationByName("imported3/feed"), "imported3/feed";
	ok my $neg3 = $graph->OperationByName("imported3/neg"), "imported3/neg";

	note q|Check that newly-imported scalar and feed have control deps (neg3 will
	inherit them from input)|;
	is $scalar3->GetControlInputs, array {
		item 0 => object { call Name => $feed->Name  };
		item 1 => object { call Name => $feed2->Name };
		end;
	}, 'scalar3 control inputs';

	is $feed3->GetControlInputs, array {
		item 0 => object { call Name => $feed->Name  };
		item 1 => object { call Name => $feed2->Name };
		end;
	}, 'feed3 control inputs';

	note 'Export to a graph def so we can import a graph with control dependencies';
	undef $graph_def;
	$graph_def = AI::TensorFlow::Libtensorflow::Buffer->New;
	$graph->ToGraphDef( $graph_def, $s );
	TF_Utils::AssertStatusOK($s);

	note 'Import again, with remapped control dependency, into the same graph';
	undef $opts;
	$opts = AI::TensorFlow::Libtensorflow::ImportGraphDefOptions->New;
	$opts->SetPrefix("imported4");
	$opts->RemapControlDependency("imported/feed", $feed );
	$graph->ImportGraphDef($graph_def, $opts, $s);
	TF_Utils::AssertStatusOK($s);

	ok my $scalar4 = $graph->OperationByName("imported4/imported3/scalar"),
		"imported4/imported3/scalar";
	ok my $feed4 = $graph->OperationByName("imported4/imported2/feed"),
		"imported4/imported2/feed";

	note q|Check that imported `imported3/scalar` has remapped control dep from
	original graph and imported control dep|;
	is $scalar4->GetControlInputs, array {
		item object { call Name => $feed->Name  };
		item object { call Name => $feed4->Name };
		end;
	}, 'scalar4 control inputs';

	undef $opts;
	undef $graph_def;

	note 'Can add nodes to the imported graph without trouble.';
	TF_Utils::Add( $feed, $scalar, $graph, $s );
	TF_Utils::AssertStatusOK($s);
};

done_testing;



( run in 1.281 second using v1.01-cache-2.11-cpan-97f6503c9c8 )