private NDArray _run <T>(T fetches, Dictionary <Tensor, NDArray> feed_dict = null) { var feed_dict_tensor = new Dictionary <Tensor, NDArray>(); if (feed_dict != null) { foreach (var feed in feed_dict) { feed_dict_tensor[feed.Key] = feed.Value; } } // Create a fetch handler to take care of the structure of fetches. var fetch_handler = new _FetchHandler <T>(_graph, fetches, feed_dict_tensor); // Run request and get response. // We need to keep the returned movers alive for the following _do_run(). // These movers are no longer needed when _do_run() completes, and // are deleted when `movers` goes out of scope when this _run() ends. var _ = _update_with_movers(); var final_fetches = fetch_handler.fetches(); var final_targets = fetch_handler.targets(); // We only want to really perform the run if fetches or targets are provided, // or if the call is a partial run that specifies feeds. var results = _do_run(final_targets.Select(x => (Operation)(object)x).ToList(), final_fetches, feed_dict_tensor); return(fetch_handler.build_results(null, results)); }
private NDArray _run(object fetches, FeedItem[] feed_dict = null) { var feed_dict_tensor = new Dictionary <object, object>(); var feed_map = new Dictionary <object, object>(); // Validate and process feed_dict. if (feed_dict != null) { foreach (var subfeed in feed_dict) { var subfeed_t = _graph.as_graph_element(subfeed.Key, allow_tensor: true, allow_operation: false); var subfeed_dtype = subfeed_t.dtype.as_numpy_datatype(); switch (subfeed.Value) { case float floatVal: feed_dict_tensor[subfeed_t] = (NDArray)floatVal; break; case int intVal: feed_dict_tensor[subfeed_t] = (NDArray)intVal; break; case string str: feed_dict_tensor[subfeed_t] = (NDArray)str; break; default: throw new NotImplementedException("_run subfeed"); } feed_map[subfeed_t.name] = (subfeed_t, subfeed.Value); } } // Create a fetch handler to take care of the structure of fetches. var fetch_handler = new _FetchHandler(_graph, fetches, feed_dict_tensor); // Run request and get response. // We need to keep the returned movers alive for the following _do_run(). // These movers are no longer needed when _do_run() completes, and // are deleted when `movers` goes out of scope when this _run() ends. var _ = _update_with_movers(); var final_fetches = fetch_handler.fetches(); var final_targets = fetch_handler.targets(); // We only want to really perform the run if fetches or targets are provided, // or if the call is a partial run that specifies feeds. var results = _do_run(final_targets.Select(x => (Operation)(object)x).ToList(), final_fetches, feed_dict_tensor); return(fetch_handler.build_results(this, results)); }
private unsafe object _run(Tensor fetches, Dictionary <Tensor, object> feed_dict = null) { var feed_dict_tensor = new Dictionary <Tensor, NDArray>(); if (feed_dict != null) { NDArray np_val = null; foreach (var feed in feed_dict) { switch (feed.Value) { case float value: np_val = np.asarray(value); break; } feed_dict_tensor[feed.Key] = np_val; } } // Create a fetch handler to take care of the structure of fetches. var fetch_handler = new _FetchHandler(_graph, fetches); // Run request and get response. // We need to keep the returned movers alive for the following _do_run(). // These movers are no longer needed when _do_run() completes, and // are deleted when `movers` goes out of scope when this _run() ends. var _ = _update_with_movers(); var final_fetches = fetch_handler.fetches(); var final_targets = fetch_handler.targets(); // We only want to really perform the run if fetches or targets are provided, // or if the call is a partial run that specifies feeds. var results = _do_run(final_fetches); return(fetch_handler.build_results(null, results)); }