Workspace workSpace;
NetDef initNet, predictNet;
- static std::map <char*, Tensor*> inputTensorMap;
+ std::map <char*, Tensor*> inputTensorMap;
int initInputTensor ();
};
void init_filter_caffe2 (void) __attribute__ ((constructor));
void fini_filter_caffe2 (void) __attribute__ ((destructor));
-std::map <char*, Tensor*> Caffe2Core::inputTensorMap;
-
/**
* @brief Caffe2Core creator
* @param _model_path : the logical path to '{model_name}.tffile' file
int run (const GstTensorMemory * input, GstTensorMemory * output);
int parseOutputTensors(PyObject* result, GstTensorsInfo * info);
+ void freeOutputTensors(void *data);
/** @brief Return callback type */
cb_type getCbType () { return callback_type; }
tensor_type getTensorType (NPY_TYPES npyType);
NPY_TYPES getNumpyType (tensor_type tType);
- static std::map <void*, PyArrayObject*> outputArrayMap;
private:
const std::string script_path; /**< from model_path property */
const std::string module_args; /**< from custom property */
std::string module_name;
+ std::map <void*, PyArrayObject*> outputArrayMap;
cb_type callback_type;
void init_filter_py (void) __attribute__ ((constructor));
void fini_filter_py (void) __attribute__ ((destructor));
-std::map <void*, PyArrayObject*> PYCore::outputArrayMap;
-
/**
* @brief PYCore creator
* @param _script_path : the logical path to '{script_name}.py' file
}
/**
+ * @brief free output tensor corresponding to the given data
+ * @param[data] The data element
+ */
+void
+PYCore::freeOutputTensors (void *data)
+{
+ std::map <void*, PyArrayObject*>::iterator it;
+
+ it = outputArrayMap.find(data);
+ if (it != outputArrayMap.end()){
+ Py_XDECREF(it->second);
+ outputArrayMap.erase (it);
+ } else {
+ g_critical("Cannot find output data: 0x%lx", (unsigned long) data);
+ }
+}
+
+/**
* @brief run the script with the input.
* @param[in] input : The array of input tensors
* @param[out] output : The array of output tensors
static void
py_destroyNotify (void **private_data, void *data)
{
- std::map <void*, PyArrayObject*>::iterator it;
- it = PYCore::outputArrayMap.find(data);
- if (it != PYCore::outputArrayMap.end()){
- Py_XDECREF(it->second);
- PYCore::outputArrayMap.erase (it);
- } else {
- g_critical("Cannot find output data: 0x%lx", (unsigned long) data);
+ PYCore *core = static_cast<PYCore *>(*private_data);
+
+ if (core) {
+ core->freeOutputTensors (data);
}
}
int getInputTensorDim (GstTensorsInfo * info);
int getOutputTensorDim (GstTensorsInfo * info);
int run (const GstTensorMemory * input, GstTensorMemory * output);
-
- static std::map < void *, TF_Tensor * >outputTensorMap;
+ void freeOutputTensor (void *data);
private:
GstTensorsInfo outputTensorMeta; /**< The tensor info of output tensors from user input */
std::vector < tf_tensor_info_s > input_tensor_info; /* hold information for TF */
+ std::map < void *, TF_Tensor * > outputTensorMap;
TF_Graph *graph;
TF_Session *session;
void init_filter_tf (void) __attribute__ ((constructor));
void fini_filter_tf (void) __attribute__ ((destructor));
-std::map <void*, TF_Tensor*> TFCore::outputTensorMap;
-
/**
* @brief TFCore creator
* @param _model_path : the logical path to '{model_name}.pb' file
}
/**
+ * @brief free output tensor corresponding to the given data
+ * @param[in] data The data element
+ */
+void
+TFCore::freeOutputTensor (void *data)
+{
+ TF_Tensor *output_tensor = outputTensorMap.find (data)->second;
+ TF_DeleteTensor (output_tensor);
+ outputTensorMap.erase (data);
+}
+
+/**
* @brief Free privateData and move on.
*/
static void
static void
tf_destroyNotify (void **private_data, void *data)
{
- TF_DeleteTensor ( (TFCore::outputTensorMap.find (data))->second);
- TFCore::outputTensorMap.erase (data);
+ TFCore *core = static_cast<TFCore *>(*private_data);
+
+ if (core) {
+ core->freeOutputTensor (data);
+ }
}
static gchar filter_subplugin_tensorflow[] = "tensorflow";