1. add new method to set/get the property in single-shot.
2. add/modify testcases for snap and property value.
Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
/* let's ignore timeout (set 60 sec) */
single.setTimeout(60000);
+ /* set layout */
+ single.setProperty("inputlayout", "NHWC");
+ single.setProperty("outputlayout", "NCHW");
+
/* single-shot invoke */
for (int i = 0; i < 10; i++) {
/* dummy input */
"other/tensor,dimension=(string)3:224:224:1,type=(string)float32,framerate=(fraction)0/1 ! " +
"tensor_filter framework=snap " +
"model=" + models[0].getAbsolutePath() + "," + models[1].getAbsolutePath() + " " +
- "input=3:224:224:1 inputtype=float32 inputname=data " +
- "output=1:1:1000:1 outputtype=float32 outputname=prob " +
+ "input=3:224:224:1 inputtype=float32 inputlayout=NHWC inputname=data " +
+ "output=1:1:1000:1 outputtype=float32 outputlayout=NCHW outputname=prob " +
"custom=" + option + " ! " +
"tensor_sink name=sinkx";
/* expected */
}
}
+
+ @Test
+ public void testGetInvalidPropertyName_n() {
+ try {
+ mSingle.getProperty("");
+ fail();
+ } catch (Exception e) {
+ /* expected */
+ }
+ }
+
+ @Test
+ public void testGetUnknownPropertyName_n() {
+ try {
+ mSingle.getProperty("unknown_prop");
+ fail();
+ } catch (Exception e) {
+ /* expected */
+ }
+ }
+
+ @Test
+ public void testGetNullPropertyName_n() {
+ try {
+ mSingle.getProperty(null);
+ fail();
+ } catch (Exception e) {
+ /* expected */
+ }
+ }
+
+ @Test
+ public void testUnknownPropertyName_n() {
+ try {
+ mSingle.setProperty("unknown_prop", "unknown");
+ fail();
+ } catch (Exception e) {
+ /* expected */
+ }
+ }
+
+ @Test
+ public void testSetNullPropertyName_n() {
+ try {
+ mSingle.setProperty(null, "ANY");
+ fail();
+ } catch (Exception e) {
+ /* expected */
+ }
+ }
+
+ @Test
+ public void testSetNullPropertyValue_n() {
+ try {
+ mSingle.setProperty("inputlayout", null);
+ fail();
+ } catch (Exception e) {
+ /* expected */
+ }
+ }
+
+ @Test
+ public void testGetPropertyDimension() {
+ try {
+ assertEquals("3:224:224:1", mSingle.getProperty("input"));
+ assertEquals("1001:1:1:1", mSingle.getProperty("output"));
+ } catch (Exception e) {
+ fail();
+ }
+ }
}
private native TensorsData nativeInvoke(long handle, TensorsData in);
private native TensorsInfo nativeGetInputInfo(long handle);
private native TensorsInfo nativeGetOutputInfo(long handle);
+ private native boolean nativeSetProperty(long handle, String name, String value);
+ private native String nativeGetProperty(long handle, String name);
private native boolean nativeSetInputInfo(long handle, TensorsInfo in);
private native boolean nativeSetTimeout(long handle, int timeout);
}
/**
+ * Sets the property value for the given model.
+ * Note that a model/framework may not support to change the property after opening the model.
+ *
+ * @param name The property name
+ * @param value The property value
+ *
+ * @throws IllegalArgumentException if given param is invalid
+ */
+ public void setProperty(@NonNull String name, @NonNull String value) {
+ if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException("Given property name is invalid");
+ }
+
+ if (value == null || value.isEmpty()) {
+ throw new IllegalArgumentException("Given property value is invalid");
+ }
+
+ if (!nativeSetProperty(mHandle, name, value)) {
+ throw new IllegalArgumentException("Failed to set the property");
+ }
+ }
+
+ /**
+ * Gets the property value for the given model.
+ *
+ * @param name The property name
+ *
+ * @return The property value
+ *
+ * @throws IllegalArgumentException if given param is invalid
+ */
+ public String getProperty(@NonNull String name) {
+ if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException("Given property name is invalid");
+ }
+
+ String value = nativeGetProperty(mHandle, name);
+
+ if (value == null || value.isEmpty()) {
+ throw new IllegalArgumentException("Failed to get the property");
+ }
+
+ return value;
+ }
+
+ /**
* Sets the maximum amount of time to wait for an output, in milliseconds.
*
* @param timeout The time to wait for an output
* @brief Native method for single-shot API.
*/
jboolean
+Java_org_nnsuite_nnstreamer_SingleShot_nativeSetProperty (JNIEnv * env,
+ jobject thiz, jlong handle, jstring name, jstring value)
+{
+ pipeline_info_s *pipe_info;
+ ml_single_h single;
+ jboolean ret = JNI_FALSE;
+
+ const char *prop_name = (*env)->GetStringUTFChars (env, name, NULL);
+ const char *prop_value = (*env)->GetStringUTFChars (env, value, NULL);
+
+ pipe_info = CAST_TO_TYPE (handle, pipeline_info_s*);
+ single = pipe_info->pipeline_handle;
+
+ if (ml_single_set_property (single, prop_name, prop_value) == ML_ERROR_NONE) {
+ ret = JNI_TRUE;
+ } else {
+ nns_loge ("Failed to set the property (%s:%s).", prop_name, prop_value);
+ }
+
+ (*env)->ReleaseStringUTFChars (env, name, prop_name);
+ (*env)->ReleaseStringUTFChars (env, name, prop_value);
+ return ret;
+}
+
+/**
+ * @brief Native method for single-shot API.
+ */
+jstring
+Java_org_nnsuite_nnstreamer_SingleShot_nativeGetProperty (JNIEnv * env,
+ jobject thiz, jlong handle, jstring name)
+{
+ pipeline_info_s *pipe_info;
+ ml_single_h single;
+
+ const char *prop_name = (*env)->GetStringUTFChars (env, name, NULL);
+ char *prop_value = NULL;
+ jstring value = NULL;
+
+ pipe_info = CAST_TO_TYPE (handle, pipeline_info_s*);
+ single = pipe_info->pipeline_handle;
+
+ if (ml_single_get_property (single, prop_name, &prop_value) == ML_ERROR_NONE) {
+ value = (*env)->NewStringUTF (env, prop_value);
+ g_free (prop_value);
+ } else {
+ nns_loge ("Failed to get the property (%s).", prop_name);
+ }
+
+ (*env)->ReleaseStringUTFChars (env, name, prop_name);
+ return value;
+}
+
+/**
+ * @brief Native method for single-shot API.
+ */
+jboolean
Java_org_nnsuite_nnstreamer_SingleShot_nativeSetTimeout (JNIEnv * env,
jobject thiz, jlong handle, jint timeout)
{