GstMetaTensor *
gst_append_tensor (GstBuffer * buffer, GstMemory * mem, tensor_dim * dim)
{
- GstMemory *mem_dimension;
- GstMapInfo info;
+ tensor_dim *d;
+ GstMapInfo dest_info;
+ gst_buffer_map (buffer, &dest_info, GST_MAP_WRITE);
+ g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
+
+ gst_buffer_append_memory (buffer, mem);
GstMetaTensor *meta = GST_META_TENSOR_GET (buffer);
if (!meta) {
meta = gst_make_tensors (buffer);
}
- gst_buffer_append_memory (buffer, mem);
+
meta->num_tensors = meta->num_tensors + 1;
- mem_dimension = gst_allocator_alloc (NULL, sizeof(tensor_dim), NULL);
- gst_memory_map (mem_dimension, &info, GST_MAP_WRITE);
- memcpy (info.data, dim, sizeof(tensor_dim));
+ d = g_slice_new (tensor_dim);
+ memcpy (d, dim, sizeof (tensor_dim));
+ meta->dimensions = g_list_append (meta->dimensions, d);
- meta->dimensions = g_list_append (meta->dimensions, info.data);
- gst_memory_unmap (mem_dimension, &info);
return meta;
}
gst_get_tensor (GstBuffer * buffer, gint nth)
{
GstMetaTensor *meta;
+ GstMemory *mem;
meta = (GstMetaTensor *) gst_buffer_get_meta_tensor (buffer);
- if (!meta)
+ if (!meta) {
return (GstMemory *) buffer;
- else
- return gst_buffer_get_memory (buffer, nth);
+ } else {
+ mem = gst_buffer_get_memory (buffer, nth);
+ return mem;
+ }
}
tensor_dim *
gst_get_tensordim (GstBuffer * buffer, gint nth)
{
GstMetaTensor *meta;
+ tensor_dim *dim;
meta = (GstMetaTensor *) gst_buffer_get_meta_tensor (buffer);
- if (meta)
- return (tensor_dim *) g_list_nth_data (meta->dimensions, nth);
- else
+ if (meta) {
+ dim = (tensor_dim *) g_list_nth_data (meta->dimensions, nth);
+ return dim;
+ } else {
return NULL;
+ }
}
GstFlowReturn
Source1001: nnstreamer.manifest
Source2001: testcase_tensor_converter.tar.gz
Source2002: testcase_tensor_decoder.tar.gz
+Source2003: testcase_tensors.tar.gz
Requires: gstreamer >= 1.8.0
Requires: libdlog
tar -xf %{SOURCE2002}
popd
-cp nnstreamer_decoder/testcase01_RGB_642x480.png nnstreamer_tensors
+pushd nnstreamer_tensors
+tar -xf %{SOURCE2003}
+popd
export SKIPGEN=YES
./testAll.sh
img.save('testcase01_'+colorType+'_'+str(width)+'x'+str(height)+'.png')
return (string, string_size, expected_size)
-genCase01_PNG_random('RGB', 642, 480)
+def write(filename, string):
+ newfile = open(filename, 'wb')
+ newfile.write(string)
+
+write('testcase01_RGB_640x480.golden', genCase01_PNG_random('RGB', 640, 480)[0])
sopath=$1
fi
-gstTest "--gst-plugin-path=../../build/tests/nnstreamer_tensors/tensors_test filesrc location=testcase01_RGB_642x480.png ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,width=642,height=480,framerate=0/1 ! testtensors silent=TRUE ! tensorscheck ! filesink location=\"testcase01_RGB_642x480.nonip.log\" sync=true"
+gstTest "--gst-plugin-path=../../build/tests/nnstreamer_tensors/tensors_test filesrc location=testcase01_RGB_640x480.png ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,width=640,height=480,framerate=0/1 ! testtensors silent=TRUE ! tensorscheck ! filesink location=\"testcase01_RGB_640x480.nonip.log\" sync=true" 1
+
+compareAllSizeLimit testcase01_RGB_640x480.golden testcase01_RGB_640x480.nonip.log 1
report
/**
* SECTION:element-tensorscheck
*
- * FIXME:Describe tensorscheck here.
+ * This is the element to test tensors only.
*
* <refsect2>
* <title>Example launch line</title>
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("ANY")
+ GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT)
);
#define gst_tensorscheck_parent_class parent_class
GstStructure *s = gst_caps_get_structure (caps, 0);
gst_structure_get_int (s, "rank", &filter->rank);
- printf ("%d\n", filter->rank);
gst_structure_get_int (s, "dim1", &dim);
filter->dimension[0] = dim;
gst_structure_get_int (s, "dim2", &dim);
GstBuffer *outbuf;
gint num_tensors;
GstMapInfo info, src_info, dest_info;
- GstMemory *mem;
GstMemory *buffer_mem;
tensor_dim *dim;
unsigned int d0, d1, d2;
+ gboolean ret;
- outbuf = gst_buffer_new ();
+ /* Mapping input buffer (tensors) into src_info */
gst_buffer_map (inbuf, &src_info, GST_MAP_READ);
- num_tensors = gst_get_num_tensors (inbuf);
- printf ("num tensors : %d\n", num_tensors);
- mem = gst_get_tensor (inbuf, 0);
- dim = gst_get_tensordim (inbuf, 0);
- buffer_mem = gst_allocator_alloc (NULL, (*dim)[1] * (*dim)[2], NULL);
+
+ /* Making output GstBuffer */
+ outbuf = gst_buffer_new ();
+
+ /* Making output buffer (one big buffer for check tensors) */
+ buffer_mem =
+ gst_allocator_alloc (NULL,
+ filter->dimension[0] * filter->dimension[1] * filter->dimension[2] *
+ filter->dimension[3], NULL);
gst_buffer_append_memory (outbuf, buffer_mem);
+
gst_buffer_map (outbuf, &dest_info, GST_MAP_WRITE);
- printf ("%d %d %d %d\n", (*dim)[0], (*dim)[1], (*dim)[2], (*dim)[3]);
- gst_memory_map (mem, &info, GST_MAP_READ);
- size_t span = 0;
- for (d0 = 0; d0 < (*dim)[3]; d0++) {
- for (d1 = 0; d1 < (*dim)[2]; d1++) {
- span = d1 * (*dim)[1];
- for (d2 = 0; d2 < (*dim)[1]; d2++) {
- dest_info.data[span + d2] = info.data[span + d2 * (*dim)[0]];
+ /* Get number of tensors */
+ num_tensors = gst_get_num_tensors (inbuf);
+
+ for (int i = 0; i < num_tensors; i++) {
+ GstMemory *mem = gst_get_tensor (inbuf, i);
+ gst_memory_unref (mem);
+ dim = gst_get_tensordim (inbuf, i);
+ ret = gst_memory_map (mem, &info, GST_MAP_WRITE);
+
+ if (!ret)
+ return NULL;
+ size_t span = 0;
+ size_t span1 = 0;
+ for (d0 = 0; d0 < (*dim)[3]; d0++) {
+ for (d1 = 0; d1 < (*dim)[2]; d1++) {
+ span = d1 * (*dim)[1];
+ span1 = d1 * (*dim)[1] * 3;
+ for (d2 = 0; d2 < (*dim)[1]; d2++) {
+ dest_info.data[span1 + (d2 * num_tensors) + i] = info.data[span + d2];
+ }
}
}
+ gst_memory_unmap (mem, &info);
}
-
gst_buffer_unmap (inbuf, &src_info);
gst_buffer_unmap (outbuf, &dest_info);
{
GstBuffer *outbuf;
gint num_tensor;
- GstMapInfo info, src_info, dest_info;
- GstMemory *mem;
+ GstMapInfo info, src_info;
+
int d0, d1, d2;
outbuf = gst_buffer_new ();
gst_buffer_map (inbuf, &src_info, GST_MAP_READ);
- gst_buffer_map (outbuf, &dest_info, GST_MAP_WRITE);
gst_make_tensors (outbuf);
+
for (num_tensor = 0; num_tensor < filter->dimension[0]; num_tensor++) {
- mem =
+
+ GstMemory *mem =
gst_allocator_alloc (NULL, filter->dimension[1] * filter->dimension[2],
NULL);
gst_memory_map (mem, &info, GST_MAP_WRITE);
size_t span = 0;
+ size_t span1 = 0;
for (d0 = 0; d0 < filter->dimension[3]; d0++) {
g_assert (d0 == 0);
for (d1 = 0; d1 < filter->dimension[2]; d1++) {
- span = d1 * filter->dimension[1];
+ span = d1 * filter->dimension[1] * filter->dimension[0];
+ span1 = d1 * filter->dimension[1];
for (d2 = 0; d2 < filter->dimension[1]; d2++) {
- info.data[span + d2] =
+ info.data[span1 + d2] =
src_info.data[span + (d2 * filter->dimension[0]) + num_tensor];
}
}
dim[1] = filter->dimension[1];
dim[2] = filter->dimension[2];
dim[3] = 1;
- gst_append_tensor (outbuf, mem, &dim);
+
gst_memory_unmap (mem, &info);
+ gst_append_tensor (outbuf, mem, &dim);
}
gst_buffer_unmap (inbuf, &src_info);
- printf ("num_tensors = %d\n", gst_get_num_tensors (outbuf));
- tensor_dim *dim = gst_get_tensordim (outbuf, 1);
- printf ("%d %d %d %d \n", (*dim)[0], (*dim)[1], (*dim)[2], (*dim)[3]);
- gst_buffer_unmap (outbuf, &dest_info);
return outbuf;
}
return gst_pad_push (filter->srcpad, buf);
out = gst_test_tensors (filter, buf);
+
gst_buffer_unref (buf);
return gst_pad_push (filter->srcpad, out);