Skip to content

Conversation

@shrit
Copy link
Member

@shrit shrit commented Nov 2, 2024

Make STB part of mlpack.

Just a draft, to get an idea if this works with the CI

@shrit shrit requested a review from rcurtin November 2, 2024 14:51
@rcurtin
Copy link
Member

rcurtin commented Nov 2, 2024

It could also be a good idea to update LICENSE.txt: https://github.com/mlpack/mlpack/blob/master/LICENSE.txt#L35

STB is dual-licensed... both under the MIT and also it's in the public domain (which means we wouldn't have to list it in the license). But I think it might be a good idea to point it out in the license file, both to give credit to the STB authors and also so that people coming through the project have more ways to learn that we are bundling STB.

Copy link
Member

@rcurtin rcurtin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, it will be super useful to add some extra image support. My main comment is that we should use the same formats for images that data::Load gives.

Also, up to you, but do you want to separate this into two separate PRs for simplicity? One could be including STB as part of mlpack and making those CMake configuration changes, and the other one could be the resize/crop functionality that you added in the latest commit.

Copy link
Member

@rcurtin rcurtin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the STB CMake code---hopefully it's helpful. I'm looking forward to having STB bundled; it'll make life easier 😄

shrit and others added 4 commits November 17, 2024 11:10
@rcurtin
Copy link
Member

rcurtin commented Jan 30, 2025

@mlpack-jenkins test this please

1 similar comment
@shrit
Copy link
Member Author

shrit commented Feb 2, 2025

@mlpack-jenkins test this please

@rcurtin
Copy link
Member

rcurtin commented Feb 3, 2025

@mlpack-jenkins test this please

Copy link
Member

@rcurtin rcurtin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. There is a bug with the conv_to in the image resize functionality (take a look, I think I have the fix in the comments), and there are a few simple optimizations I think we can make. It's late now so I won't try it, but I will do it tomorrow when I get up unless you get to it first (I think all my suggested fixes should work directly, take a look and let me know what you think). Glad to get this merged, sorry I have had so many tedious comments throughout 😄

Comment on lines 107 to 110
arma::fmat tempDestFloat(newDimension, 1);
stbir_resize_float_linear(images.colptr(i), info.Width(), info.Height(),
0, tempDestFloat.memptr(), newWidth, newHeight, 0, channels);
resizedFloatImages.col(i) = std::move(tempDestFloat);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arma::fmat tempDestFloat(newDimension, 1);
stbir_resize_float_linear(images.colptr(i), info.Width(), info.Height(),
0, tempDestFloat.memptr(), newWidth, newHeight, 0, channels);
resizedFloatImages.col(i) = std::move(tempDestFloat);
stbir_resize_float_linear(images.colptr(i), info.Width(), info.Height(),
0, resizedFloatImages.colptr(i), newWidth, newHeight, 0, channels);

Comment on lines 99 to 103
arma::Mat<unsigned char> tempDest(newDimension, 1);
stbir_resize_uint8_linear(images.colptr(i), info.Width(), info.Height(),
0, tempDest.memptr(), newWidth, newHeight, 0, channels);

resizedImages.col(i) = std::move(tempDest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arma::Mat<unsigned char> tempDest(newDimension, 1);
stbir_resize_uint8_linear(images.colptr(i), info.Width(), info.Height(),
0, tempDest.memptr(), newWidth, newHeight, 0, channels);
resizedImages.col(i) = std::move(tempDest);
stbir_resize_uint8_linear(images.colptr(i), info.Width(), info.Height(),
0, resizedImages.colptr(i), newWidth, newHeight, 0, channels);

I am pretty sure that this should work. I will try it locally tomorrow, but you will wake up earlier than me so if you want you can try it too 😄

}
}

images = std::move(resizedImages);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
images = std::move(resizedImages);
images = arma::conv_to<Mat<eT>>::from(std::move(resizedImages));

We need to put the conv_to here, because resizedImages has type arma::Mat<unsigned char> and images has type arma::Mat<eT>.

Comment on lines 117 to 122
arma::Mat<unsigned char> tempDest(newDimension, 1);

stbir_resize_uint8_linear(tempSrc.colptr(i), info.Width(), info.Height(),
0, tempDest.memptr(), newWidth, newHeight, 0, channels);

resizedImages.col(i) = arma::conv_to<arma::Mat<eT>>::from(tempDest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arma::Mat<unsigned char> tempDest(newDimension, 1);
stbir_resize_uint8_linear(tempSrc.colptr(i), info.Width(), info.Height(),
0, tempDest.memptr(), newWidth, newHeight, 0, channels);
resizedImages.col(i) = arma::conv_to<arma::Mat<eT>>::from(tempDest);
stbir_resize_uint8_linear(tempSrc.colptr(i), info.Width(), info.Height(),
0, resizedImages.colptr(i), newWidth, newHeight, 0, channels);

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second approval provided automatically after 24 hours. 👍

@shrit shrit merged commit 821a95f into mlpack:master Feb 5, 2025
18 of 20 checks passed
@shrit shrit deleted the stb branch February 5, 2025 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants