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

added horizontal and vertical flip augmentations #38

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

RituRajSingh878
Copy link

Related to #21
I am adding horizontal-flip and vertical-flip augmentations in augmentation. I am opening this as a draft pr because many things are not clear to me and have to discuss it. After that, I will modify it.

@mlpack-bot
Copy link

mlpack-bot bot commented Oct 5, 2020

Thanks for opening your first pull request in this repository! Someone will review it when they have a chance. In the mean time, please be sure that you've handled the following things, to make the review process quicker and easier:

  • All code should follow the style guide
  • Documentation added for any new functionality
  • Tests added for any new functionality
  • Tests that are added follow the testing guide
  • Headers and license information added to the top of any new code files
  • HISTORY.md updated if the changes are big or user-facing
  • All CI checks should be passing

Thank you again for your contributions! 👍

{
this->VerticalFlipTransform(dataset, datapointWidth, datapointHeight,
datapointDepth, augmentations[i]);
}
else
Copy link
Author

Choose a reason for hiding this comment

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

Here I am adding directly in the for loop because I am not able to use augmentationMap. I tried to use like -

https://stackoverflow.com/questions/14419202/c-map-of-string-and-member-function-pointer but I am getting error. So if can suggest How should I use it? How should I store the function in the map?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I will give detailed review in a day or two. There are some more changes that we would need to make.

Copy link
Author

Choose a reason for hiding this comment

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

okay

Copy link
Member

Choose a reason for hiding this comment

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

Could you also share the exact error. I will take a look. Thanks.

@kartikdutt18
Copy link
Member

Hmm, I don't think we need horizontal-flip:true or false. If user wants it he will add to the string else he won't.

bool ishortiflip = false;
// Get ishortiflip.
GetHorizontalFlipParam(ishortiflip, augmentation);
// if(!ishortiflip) return ;
Copy link
Author

Choose a reason for hiding this comment

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

I will uncomment it. I have added the comment by mistake.

@RituRajSingh878
Copy link
Author

Hmm, I don't think we need horizontal-flip:true or false. If user wants it he will add to the string else he won't.

Okay, I will the change code in the next commit.

Comment on lines 216 to 236
/**
* Function to determine if augmentation has horizontal-flip function.
*
* @param augmentation Optional argument to check if a string has
* horizontal-flip substring.
*/
bool HasHorizontalFlipParam(const std::string& augmentation = "")
{
if (augmentation.length())
return augmentation.find("horizontal-flip") != std::string::npos;


// Search in augmentation vector.
for(size_t i=0; i<augmentations.size(); i++)
{
if(augmentations[i].find("horizontal-flip") != std::string::npos)
return true;
}
return false;

}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this if we use a map instead.

Copy link
Author

Choose a reason for hiding this comment

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

yes

Comment on lines 238 to 258
/**
* Function to determine if augmentation has vertical-flip function.
*
* @param augmentation Optional argument to check if a string has
* vertical-flip substring.
*/
bool HasVerticalFlipParam(const std::string& augmentation = "")
{
if (augmentation.length())
return augmentation.find("vertical-flip") != std::string::npos;


// Search in augmentation vector.
for(size_t i=0; i<augmentations.size(); i++)
{
if(augmentations[i].find("vertical-flip") != std::string::npos)
return true;
}
return false;

}
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 266 to 292
void GetHorizontalFlipParam(bool& ishortiflip,
const std::string& augmentation)
{
if (!HasHorizontalFlipParam())
return;

ishortiflip = false;

// Use regex to find true or false.
boost::regex regex{"(?:true|false)"};

// Create an iterator to find matches.
boost::sregex_token_iterator matches(augmentation.begin(),
augmentation.end(), regex, 0), end;

size_t matchesCount = std::distance(matches, end);

if (matchesCount == 1)
{
ishortiflip = (*matches) == "true" ? true:false;
}
else
{
mlpack::Log::Fatal << "Invalid boolean value in " <<
augmentation << std::endl;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

If we remove the need for true and false, assume we need to flip if there is horizontal flip then we can remove this as well.

Copy link
Author

Choose a reason for hiding this comment

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

yes

* @param isvertiflip Output is verticalr flipped or not.
* @param augmentation String from boolean value is extracted.
*/
void GetVerticalFlipParam(bool& isvertiflip,
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Copy link
Member

@kartikdutt18 kartikdutt18 left a comment

Choose a reason for hiding this comment

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

Hey @RituRajSingh878, There are some changes that we need to make here. Let me know what you think. Thanks for working on this. Once we fix that error and remove the unnecessary part of the code we should be able to merge this.
Thanks.

@RituRajSingh878
Copy link
Author

 
  for(size_t i = 0; i < augmentations.size(); i++)
  {
    if( augmentations[i] == "horizontal-flip")
    augmentationMap[augmentations[i]] = &Augmentation::HorizontalFlipTransform;
  }

I am doing smothing like this and getting the following error. I am not sure how should I use add it and where should I add it? I guess, I am doing something wrong and don't know how to use it properly. So if you can explain and suggest something.

home/rituraj/models/tests/augmentation_tests.cpp:32:63:   required from here
/home/rituraj/models/tests/../augmentation/augmentation_impl.hpp:32:39: error: no matches converting function ‘HorizontalFlipTransform’ to type ‘std::unordered_map<std::__cxx11::basic_string<char>, void (*)(arma::Mat<double>&, long unsigned int, long unsigned int, long unsigned int, std::__cxx11::basic_string<char>&), std::hash<std::__cxx11::basic_string<char> >, std::equal_to<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const std::__cxx11::basic_string<char>, void (*)(arma::Mat<double>&, long unsigned int, long unsigned int, long unsigned int, std::__cxx11::basic_string<char>&)> > >::mapped_type {aka void (*)(class arma::Mat<double>&, long unsigned int, long unsigned int, long unsigned int, class std::__cxx11::basic_string<char>&)}’
     augmentationMap[augmentations[i]] = &Augmentation::HorizontalFlipTransform;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from /home/rituraj/models/tests/augmentation_tests.cpp:14:0:
/home/rituraj/models/tests/../augmentation/augmentation.hpp:124:8: note: candidate is: template<class DatasetType> void Augmentation::HorizontalFlipTransform(DatasetType&, size_t, size_t, size_t, const string&)
   void HorizontalFlipTransform(DatasetType& dataset,
        ^~~~~~~~~~~~~~~~~~~~~~~
tests/CMakeFiles/models_test.dir/build.make:62: recipe for target 'tests/CMakeFiles/models_test.dir/augmentation_tests.cpp.o' failed
make[2]: *** [tests/CMakeFiles/models_test.dir/augmentation_tests.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....

@mlpack-bot
Copy link

mlpack-bot bot commented Nov 6, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! 👍

@mlpack-bot
Copy link

mlpack-bot bot commented Dec 10, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! 👍

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