def testComputeRFFromGraphDefUnalignedFixedInputDim(self): graph_def = create_test_network_4().as_graph_def() input_node = 'input_image' output_node = 'output' with self.assertRaises(ValueError): receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node, input_resolution=[8, 8])
def testComputeCoordinatesRoundtrip(self): graph_def = create_test_network_1() input_node = 'input_image' output_node = 'output' rf = receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node) x = np.random.randint(0, 100, (50, 2)) y = rf.compute_feature_coordinates(x) x2 = rf.compute_input_center_coordinates(y) self.assertAllEqual(x, x2)
def testComputeRFFromGraphDefWithIntermediateAddNode(self): graph_def = create_test_network_8().as_graph_def() input_node = 'input_image' output_node = 'output' (receptive_field_x, receptive_field_y, effective_stride_x, effective_stride_y, effective_padding_x, effective_padding_y) = ( receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node)) self.assertEqual(receptive_field_x, 11) self.assertEqual(receptive_field_y, 11) self.assertEqual(effective_stride_x, 8) self.assertEqual(effective_stride_y, 8) self.assertEqual(effective_padding_x, 5) self.assertEqual(effective_padding_y, 5)
def testComputeRFFromGraphDefAlignedWithControlDependencies(self): graph_def = create_test_network_7().as_graph_def() input_node = 'input_image' output_node = 'output' (receptive_field_x, receptive_field_y, effective_stride_x, effective_stride_y, effective_padding_x, effective_padding_y) = ( receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node)) self.assertEqual(receptive_field_x, 3) self.assertEqual(receptive_field_y, 3) self.assertEqual(effective_stride_x, 4) self.assertEqual(effective_stride_y, 4) self.assertEqual(effective_padding_x, 1) self.assertEqual(effective_padding_y, 1)
def testComputeRFFromGraphDefNonSquareRF(self): graph_def = create_test_network_5().as_graph_def() input_node = 'input_image' output_node = 'output' (receptive_field_x, receptive_field_y, effective_stride_x, effective_stride_y, effective_padding_x, effective_padding_y) = ( receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node)) self.assertEqual(receptive_field_x, 5) self.assertEqual(receptive_field_y, 7) self.assertEqual(effective_stride_x, 4) self.assertEqual(effective_stride_y, 4) self.assertEqual(effective_padding_x, 0) self.assertEqual(effective_padding_y, 0)
def testComputeRFFromGraphDefFixedInputDim(self): graph_def = create_test_network_4().as_graph_def() input_node = 'input_image' output_node = 'output' (receptive_field_x, receptive_field_y, effective_stride_x, effective_stride_y, effective_padding_x, effective_padding_y) = ( receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node, input_resolution=[9, 9])) self.assertEqual(receptive_field_x, 3) self.assertEqual(receptive_field_y, 3) self.assertEqual(effective_stride_x, 4) self.assertEqual(effective_stride_y, 4) self.assertEqual(effective_padding_x, 1) self.assertEqual(effective_padding_y, 1)
def testComputeRFFromGraphDefUndefinedPadding(self): graph_def = create_test_network_4().as_graph_def() input_node = 'input_image' output_node = 'output' (receptive_field_x, receptive_field_y, effective_stride_x, effective_stride_y, effective_padding_x, effective_padding_y) = ( receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node)) self.assertEqual(receptive_field_x, 3) self.assertEqual(receptive_field_y, 3) self.assertEqual(effective_stride_x, 4) self.assertEqual(effective_stride_y, 4) self.assertEqual(effective_padding_x, None) self.assertEqual(effective_padding_y, None)
def testComputeRFFromGraphDefStopPropagation(self): graph_def = create_test_network_6().as_graph_def() input_node = 'input_image' output_node = 'output' # Compute the receptive field but stop the propagation for the random # uniform variable of the dropout. (receptive_field_x, receptive_field_y, effective_stride_x, effective_stride_y, effective_padding_x, effective_padding_y) = ( receptive_field.compute_receptive_field_from_graph_def( graph_def, input_node, output_node, ['dropout/random_uniform'])) self.assertEqual(receptive_field_x, 3) self.assertEqual(receptive_field_y, 3) self.assertEqual(effective_stride_x, 4) self.assertEqual(effective_stride_y, 4) self.assertEqual(effective_padding_x, 1) self.assertEqual(effective_padding_y, 1)