Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method for image transformation matrix generation (more evualtion needed) #2057

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
80b5d0b
added test for transformation of linearized images
mark-p4 Jun 8, 2024
3288c00
added a dml file to calculate the image transformation matrix, the bu…
mark-p4 Jun 11, 2024
a616ba7
added a dml file img_transform_matrix.dml
mark-p4 Jul 18, 2024
5205e87
added a builtin for img_transform_matrix.dml
mark-p4 Jul 18, 2024
875c75f
added function img_transform_matrix, CP and Lop missing? maybe hop too?
mark-p4 Jul 19, 2024
36c8597
rewritten for img_transform_matrix.dml to be used
mark-p4 Jul 19, 2024
42a38a7
intermediate commit, added new test script, reimplemented function to…
mark-p4 Jul 26, 2024
9ae2b23
solid path to executing the necessary steps, throwing not implemented…
mark-p4 Jul 26, 2024
1ea9b08
added some multi return parameters
mark-p4 Jul 26, 2024
9a2a375
we made it to a state were the function itself can be implemented in …
mark-p4 Jul 26, 2024
9a4c921
first steps of implementation of the algorithm for the transformation…
mark-p4 Jul 27, 2024
e533dee
intermediate commit for transformation matrix implementation
mark-p4 Jul 27, 2024
ef83ba2
almost completed the transformation matrix implementation
mark-p4 Jul 27, 2024
36926ac
ctable is not working in any meaningful way
mark-p4 Jul 27, 2024
620e71e
image_transform_matrix.dml is now working, some testing and evaluatio…
mark-p4 Jul 28, 2024
bf120d2
cleanup of existing code for pull request
mark-p4 Jul 28, 2024
e35ea84
added approriate licences to new dml and java files
mark-p4 Jul 28, 2024
a2d0ee9
improved documentation based on automated tests
mark-p4 Jul 28, 2024
e3e06d3
disabled the transform linearized test for now, aim is to enable late…
mark-p4 Jul 28, 2024
ba4322c
changes to BuiltinImageTransformLinearizedTest.java and image_transfo…
mark-p4 Jul 28, 2024
3e2cb7d
various changes
mark-p4 Jul 29, 2024
fa7d7c1
added changes to tests and cleaned up LibMatrixIMGTransform
mark-p4 Jul 29, 2024
e32ca44
improved tests and looking into bug with the img_transform_linearized…
mark-p4 Jul 30, 2024
3ba7e55
everything seems to work, nice
mark-p4 Jul 30, 2024
e825ca1
added improvements based on feedback and cleaned up code
mark-p4 Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added a dml file to calculate the image transformation matrix, the bu…
…iltin function name, and a simple test case to trace the namespace error from a function that is not yet fully implemented, also corrected wront initial test
mark-p4 committed Jun 11, 2024
commit 3288c00627607d57eb8348019a09427d6977e5e7
1 change: 1 addition & 0 deletions src/main/java/org/apache/sysds/common/Builtins.java
Original file line number Diff line number Diff line change
@@ -168,6 +168,7 @@ public enum Builtins {
IMG_CROP_LINEARIZED("img_crop_linearized", true),
IMG_TRANSFORM("img_transform", true),
IMG_TRANSFORM_LINEARIZED("img_transform_linearized", true),
IMG_TRANSLATE_MATRIX("img_translate_matrix", false),
IMG_TRANSLATE("img_translate", true),
IMG_TRANSLATE_LINEARIZED("img_translate_linearized", true),
IMG_ROTATE("img_rotate", true),
Original file line number Diff line number Diff line change
@@ -69,17 +69,17 @@ public void setUp() {
}

@Test
public void testImageTranslateLinearized() {
runImageTranslateLinearizedTest(false, ExecType.CP);
public void testImageTransformLinearized() {
runImageTransformLinearizedTest(false, ExecType.CP);
}

@Test
@Ignore
public void testImageTranslateLinearizedSP() {
runImageTranslateLinearizedTest(true, ExecType.SPARK);
public void testImageTransformLinearizedSP() {
runImageTransformLinearizedTest(true, ExecType.SPARK);
}

private void runImageTranslateLinearizedTest(boolean sparse, ExecType instType) {
private void runImageTransformLinearizedTest(boolean sparse, ExecType instType) {
ExecMode platformOld = setExecMode(instType);
disableOutAndExpectedDeletion();

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.apache.sysds.test.functions.builtin.part1;

import org.apache.sysds.test.AutomatedTestBase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.apache.sysds.common.Types.ExecMode;
import org.apache.sysds.common.Types.ExecType;
import org.apache.sysds.test.TestConfiguration;

import java.util.Arrays;
import java.util.Collection;

@RunWith(Parameterized.class)
@net.jcip.annotations.NotThreadSafe

public class BuiltinImageTransformMatrixTest extends AutomatedTestBase {
private final static String TEST_NAME_LINEARIZED = "image_transform_matrix";
private final static String TEST_DIR = "functions/builtin/";
private final static String TEST_CLASS_DIR = TEST_DIR + BuiltinImageTransformMatrixTest.class.getSimpleName() + "/";

@Parameterized.Parameter(0)
public double[][] transMat;
@Parameterized.Parameter(1)
public double[][] dimMat;

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{new double[][] {{1,0,0},{0,1,0},{0,0,1}}, new double[][] {{512, 512},{512,512}}}});
}

@Override
public void setUp() {
addTestConfiguration(TEST_NAME_LINEARIZED,
new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_LINEARIZED, new String[] {"B_x"}));
}

@Test
public void testImageTransformMatrix() {
runImageTransformMatrixTest(ExecType.CP);
}

private void runImageTransformMatrixTest(ExecType instType) {
ExecMode platformOld = setExecMode(instType);
disableOutAndExpectedDeletion();

try {
loadTestConfiguration(getTestConfiguration(TEST_NAME_LINEARIZED));

String HOME = SCRIPT_DIR + TEST_DIR;

writeInputMatrixWithMTD("transMat", transMat, true);
writeInputMatrixWithMTD("dimMat", dimMat, true);

fullDMLScriptName = HOME + TEST_NAME_LINEARIZED + ".dml";
programArgs = new String[]{"-nvargs", "transMat=" + input("transMat"), "dimMat=" + input("dimMat"), "out_file=" + output("B_x"), "--debug"};

//double[][] A = getRandomMatrix(rows, height*width, 0, 255, sparsity, 7);


runTest(true, false, null, -1);

//HashMap<MatrixValue.CellIndex, Double> dmlfileLinearizedX = readDMLMatrixFromOutputDir("B_x");

//HashMap<MatrixValue.CellIndex, Double> dmlfileX = readDMLMatrixFromOutputDir("B_x_reshape");

//TestUtils.compareMatrices(dmlfileLinearizedX, dmlfileX, eps, "Stat-DML-LinearizedX", "Stat-DML-X");

} catch (Exception e) {
e.printStackTrace();
} finally {
rtplatform = platformOld;
}
}


}
37 changes: 37 additions & 0 deletions src/test/scripts/functions/builtin/image_transform_matrix.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#-------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#-------------------------------------------------------------

#get the transformation matrix (3x3) as an input
transformationMatrix = read($transMat)
print(toString(transformationMatrix))

#get a matrix with the original image dimensions and the target dimensions (2x2)
#-----original height----original width
#-----target height------target width
dimensionMatrix = read($dimMat)
print(toString(dimensionMatrix))

#function for calculating the matrix which will be matrix multiplied with
#the image for matrix multiplication
zMat = img_transform_matrix(transformationMatrix, dimensionMatrix)

print(toString(transformationMatrix))
write(zMat, $out_file)