#NEWLINE# @ patch ( 'nideep.eval.inference.est_min_num_fwd_passes' ) #NEWLINE# @ patch ( 'nideep.eval.inference.caffe.Net' ) #NEWLINE# def test_response_to_lmdb( self , mock_net , mock_num ) : #NEWLINE# #INDENT# b = { k : Bunch ( data = np . random . rand ( 4 , 1 , 3 , 2 ) ) for k in [ 'x' , 'y' , 'z' ] } #NEWLINE# mock_num . return_value = 3 #NEWLINE# mock_net . return_value . forward . return_value = np . zeros ( 1 ) #NEWLINE# type ( mock_net . return_value ) . blobs = PropertyMock ( return_value = b ) #NEWLINE# net = mock_net ( ) #NEWLINE# dst_prefix = os . path . join ( self . dir_tmp , 'test_response_to_lmdb_' ) #NEWLINE# for m in [ 'train' , 'test' ] : #NEWLINE# #INDENT# for k in b . keys ( ) : #NEWLINE# #INDENT# assert_false ( os . path . isdir ( ( dst_prefix + ( ( ( '%s_' + m ) + '_lmdb' ) % k ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# import nideep #NEWLINE# out = nideep . eval . inference . response_to_lmdb ( 'net.prototxt' , 'w.caffemodel' , [ 'x' , 'z' ] , dst_prefix ) #NEWLINE# assert_equal ( net . forward . call_count , ( 3 * 2 ) ) #NEWLINE# from caffe import TRAIN , TEST #NEWLINE# assert_list_equal ( out . keys ( ) , [ TRAIN , TEST ] ) #NEWLINE# assert_list_equal ( out [ TRAIN ] , ( [ ( 3 * 4 ) ] * 2 ) ) #NEWLINE# assert_list_equal ( out [ TEST ] , ( [ ( 3 * 4 ) ] * 2 ) ) #NEWLINE# for m in [ 'train' , 'test' ] : #NEWLINE# #INDENT# for k in b . keys ( ) : #NEWLINE# #INDENT# if ( k in [ 'x' , 'z' ] ) : #NEWLINE# #INDENT# assert_true ( os . path . isdir ( ( dst_prefix + ( ( ( '%s_' + m ) + '_lmdb' ) % b ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert_false ( os . path . isdir ( ( dst_prefix + ( ( ( '%s_' + m ) + '_lmdb' ) % k ) ) ) )