void CropTransformer::InitFromConfig(const ConfigParameters &config) { m_cropType = ParseCropType(config(L"cropType", "")); floatargvector cropRatio = config(L"cropRatio", "1.0"); m_cropRatioMin = cropRatio[0]; m_cropRatioMax = cropRatio[1]; if (!(0 < m_cropRatioMin && m_cropRatioMin <= 1.0) || !(0 < m_cropRatioMax && m_cropRatioMax <= 1.0) || m_cropRatioMin > m_cropRatioMax) { RuntimeError("Invalid cropRatio value, must be > 0 and <= 1. cropMin must " "<= cropMax"); } m_jitterType = ParseJitterType(config(L"jitterType", "")); if (!config.ExistsCurrent(L"hflip")) { m_hFlip = m_cropType == CropType::Random; } else { m_hFlip = config(L"hflip"); } }
void CropTransformer::InitFromConfig(const ConfigParameters &config) { floatargvector cropRatio = config(L"cropRatio", "1.0"); m_cropRatioMin = cropRatio[0]; m_cropRatioMax = cropRatio[1]; if (!(0 < m_cropRatioMin && m_cropRatioMin <= 1.0) || !(0 < m_cropRatioMax && m_cropRatioMax <= 1.0) || m_cropRatioMin > m_cropRatioMax) { RuntimeError("Invalid cropRatio value, must be > 0 and <= 1. cropMin must " "<= cropMax"); } m_jitterType = ParseJitterType(config(L"jitterType", "")); if (!config.ExistsCurrent(L"hflip")) { m_hFlip = m_imageConfig->GetCropType() == CropType::Random; } else { m_hFlip = config(L"hflip"); } m_aspectRatioRadius = config(L"aspectRatioRadius", ConfigParameters::Array(doubleargvector(vector<double>{0.0}))); }
CropTransformer::CropTransformer(const ConfigParameters& config) : ImageTransformerBase(config) { intargvector cropSize = config(L"cropSize", "0"); m_cropWidth = cropSize[0]; m_cropHeight = cropSize[1]; if (m_cropWidth < 0 || m_cropHeight < 0) { RuntimeError("Invalid cropSize value, must be >= 0"); } m_useSideRatio = true; floatargvector sideRatio = config(L"sideRatio", "0.0"); m_sideRatioMin = sideRatio[0]; m_sideRatioMax = sideRatio[1]; if (m_sideRatioMin == 0.0 && m_sideRatioMax == 0.0) // taking default value means not specified { m_useSideRatio = false; } else if (!(m_sideRatioMin > 0 && m_sideRatioMax <= 1.0) || m_sideRatioMin > m_sideRatioMax) { RuntimeError("Invalid sideRatio value, must be > 0 and <= 1. sideMin must <= sideMax"); } m_useAreaRatio = true; floatargvector areaRatio = config(L"areaRatio", "0.0"); m_areaRatioMin = areaRatio[0]; m_areaRatioMax = areaRatio[1]; if (m_areaRatioMin == 0.0 && m_areaRatioMax == 0.0) // taking default value means not specified { m_useAreaRatio = false; } else if (!(m_areaRatioMin > 0 && m_areaRatioMax <= 1.0) || m_areaRatioMin > m_areaRatioMax) { RuntimeError("Invalid areaRatio value, must be > 0 and <= 1. areaMin must <= areaMax"); } if (m_useSideRatio && m_useAreaRatio) RuntimeError("sideRatio and areaRatio cannot be specified simultaneously"); floatargvector aspectRatio = config(L"aspectRatio", "1.0"); m_aspectRatioMin = aspectRatio[0]; m_aspectRatioMax = aspectRatio[1]; if (!(m_aspectRatioMin > 0 && m_aspectRatioMax <= 1.0) || m_aspectRatioMin > m_aspectRatioMax) { RuntimeError("Invalid aspectRatio value, must be > 0 and <= 1. aspectMin must <= aspectMax"); } m_jitterType = ParseJitterType(config(L"jitterType", "")); m_cropType = ImageConfigHelper::ParseCropType(config(L"cropType", "")); if (!config.ExistsCurrent(L"hflip")) { m_hFlip = (m_cropType == CropType::RandomSide || m_cropType == CropType::RandomArea); } else { m_hFlip = config(L"hflip"); } // for MultiView10 we need to set m_hflip = false, otherwise we might not get 5 unflipped image (see CropTransformer::Apply below) if (m_cropType == CropType::MultiView10) { m_hFlip = false; } }