@ -58,7 +58,7 @@ def test_auto_contrast_py(plot=False):
transforms_auto_contrast = F . ComposeOp ( [ F . Decode ( ) ,
transforms_auto_contrast = F . ComposeOp ( [ F . Decode ( ) ,
F . Resize ( ( 224 , 224 ) ) ,
F . Resize ( ( 224 , 224 ) ) ,
F . AutoContrast ( ) ,
F . AutoContrast ( cutoff = 10.0 , ignore = [ 10 , 20 ] ) ,
F . ToTensor ( ) ] )
F . ToTensor ( ) ] )
ds_auto_contrast = ds . map ( input_columns = " image " ,
ds_auto_contrast = ds . map ( input_columns = " image " ,
@ -99,8 +99,8 @@ def test_auto_contrast_c(plot=False):
ds = ds . map ( input_columns = [ " image " ] ,
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ C . Decode ( ) ,
operations = [ C . Decode ( ) ,
C . Resize ( ( 224 , 224 ) ) ] )
C . Resize ( ( 224 , 224 ) ) ] )
python_op = F . AutoContrast ( )
python_op = F . AutoContrast ( cutoff = 10.0 , ignore = [ 10 , 20 ] )
c_op = C . AutoContrast ( )
c_op = C . AutoContrast ( cutoff = 10.0 , ignore = [ 10 , 20 ] )
transforms_op = F . ComposeOp ( [ lambda img : F . ToPIL ( ) ( img . astype ( np . uint8 ) ) ,
transforms_op = F . ComposeOp ( [ lambda img : F . ToPIL ( ) ( img . astype ( np . uint8 ) ) ,
python_op ,
python_op ,
np . array ] ) ( )
np . array ] ) ( )
@ -143,6 +143,10 @@ def test_auto_contrast_c(plot=False):
logger . info ( " MSE= {} " . format ( str ( np . mean ( mse ) ) ) )
logger . info ( " MSE= {} " . format ( str ( np . mean ( mse ) ) ) )
np . testing . assert_equal ( np . mean ( mse ) , 0.0 )
np . testing . assert_equal ( np . mean ( mse ) , 0.0 )
# Compare with expected md5 from images
filename = " autcontrast_01_result_c.npz "
save_and_check_md5 ( ds_auto_contrast_c , filename , generate_golden = GENERATE_GOLDEN )
if plot :
if plot :
visualize_list ( images_auto_contrast_c , images_auto_contrast_py , visualize_mode = 2 )
visualize_list ( images_auto_contrast_c , images_auto_contrast_py , visualize_mode = 2 )
@ -209,11 +213,11 @@ def test_auto_contrast_one_channel_c(plot=False):
visualize_list ( images_auto_contrast_c , images_auto_contrast_py , visualize_mode = 2 )
visualize_list ( images_auto_contrast_c , images_auto_contrast_py , visualize_mode = 2 )
def test_auto_contrast_invalid_i nput _c( ) :
def test_auto_contrast_invalid_i gnore_param _c( ) :
"""
"""
Test AutoContrast C Op with invalid params
Test AutoContrast C Op with invalid ignore parameter
"""
"""
logger . info ( " Test AutoContrast C Op with invalid params " )
logger . info ( " Test AutoContrast C Op with invalid ignore parameter " )
try :
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
ds = ds . map ( input_columns = [ " image " ] ,
@ -226,10 +230,110 @@ def test_auto_contrast_invalid_input_c():
except TypeError as error :
except TypeError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Argument ignore with value 255.5 is not of type " in str ( error )
assert " Argument ignore with value 255.5 is not of type " in str ( error )
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ C . Decode ( ) ,
C . Resize ( ( 224 , 224 ) ) ,
lambda img : np . array ( img [ : , : , 0 ] ) ] )
# invalid ignore
ds = ds . map ( input_columns = " image " ,
operations = C . AutoContrast ( ignore = ( 10 , 100 ) ) )
except TypeError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Argument ignore with value (10,100) is not of type " in str ( error )
def test_auto_contrast_invalid_cutoff_param_c ( ) :
"""
Test AutoContrast C Op with invalid cutoff parameter
"""
logger . info ( " Test AutoContrast C Op with invalid cutoff parameter " )
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ C . Decode ( ) ,
C . Resize ( ( 224 , 224 ) ) ,
lambda img : np . array ( img [ : , : , 0 ] ) ] )
# invalid ignore
ds = ds . map ( input_columns = " image " ,
operations = C . AutoContrast ( cutoff = - 10.0 ) )
except ValueError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Input cutoff is not within the required interval of (0 to 100). " in str ( error )
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ C . Decode ( ) ,
C . Resize ( ( 224 , 224 ) ) ,
lambda img : np . array ( img [ : , : , 0 ] ) ] )
# invalid ignore
ds = ds . map ( input_columns = " image " ,
operations = C . AutoContrast ( cutoff = 120.0 ) )
except ValueError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Input cutoff is not within the required interval of (0 to 100). " in str ( error )
def test_auto_contrast_invalid_ignore_param_py ( ) :
"""
Test AutoContrast python Op with invalid ignore parameter
"""
logger . info ( " Test AutoContrast python Op with invalid ignore parameter " )
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ F . ComposeOp ( [ F . Decode ( ) ,
F . Resize ( ( 224 , 224 ) ) ,
F . AutoContrast ( ignore = 255.5 ) ,
F . ToTensor ( ) ] ) ] )
except TypeError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Argument ignore with value 255.5 is not of type " in str ( error )
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ F . ComposeOp ( [ F . Decode ( ) ,
F . Resize ( ( 224 , 224 ) ) ,
F . AutoContrast ( ignore = ( 10 , 100 ) ) ,
F . ToTensor ( ) ] ) ] )
except TypeError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Argument ignore with value (10,100) is not of type " in str ( error )
def test_auto_contrast_invalid_cutoff_param_py ( ) :
"""
Test AutoContrast python Op with invalid cutoff parameter
"""
logger . info ( " Test AutoContrast python Op with invalid cutoff parameter " )
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ F . ComposeOp ( [ F . Decode ( ) ,
F . Resize ( ( 224 , 224 ) ) ,
F . AutoContrast ( cutoff = - 10.0 ) ,
F . ToTensor ( ) ] ) ] )
except ValueError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Input cutoff is not within the required interval of (0 to 100). " in str ( error )
try :
ds = de . ImageFolderDatasetV2 ( dataset_dir = DATA_DIR , shuffle = False )
ds = ds . map ( input_columns = [ " image " ] ,
operations = [ F . ComposeOp ( [ F . Decode ( ) ,
F . Resize ( ( 224 , 224 ) ) ,
F . AutoContrast ( cutoff = 120.0 ) ,
F . ToTensor ( ) ] ) ] )
except ValueError as error :
logger . info ( " Got an exception in DE: {} " . format ( str ( error ) ) )
assert " Input cutoff is not within the required interval of (0 to 100). " in str ( error )
if __name__ == " __main__ " :
if __name__ == " __main__ " :
test_auto_contrast_py ( plot = True )
test_auto_contrast_py ( plot = True )
test_auto_contrast_c ( plot = True )
test_auto_contrast_c ( plot = True )
test_auto_contrast_one_channel_c ( plot = True )
test_auto_contrast_one_channel_c ( plot = True )
test_auto_contrast_invalid_input_c ( )
test_auto_contrast_invalid_ignore_param_c ( )
test_auto_contrast_invalid_ignore_param_py ( )
test_auto_contrast_invalid_cutoff_param_c ( )
test_auto_contrast_invalid_cutoff_param_py ( )