本文整理汇总了Python中tensorflow.contrib.training.python.training.hparam.parse_values函数的典型用法代码示例。如果您正苦于以下问题:Python parse_values函数的具体用法?Python parse_values怎么用?Python parse_values使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_values函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testParseValuesWithIndexAssigment2_IgnoreUnknown
def testParseValuesWithIndexAssigment2_IgnoreUnknown(self):
"""Assignment to multiple index positions."""
parse_dict = hparam.parse_values(
'arr[0]=10,arr[5]=20,foo=bar', {'arr': int}, ignore_unknown=True)
self.assertEqual(len(parse_dict), 1)
self.assertTrue(isinstance(parse_dict['arr'], dict))
self.assertDictEqual(parse_dict['arr'], {0: 10, 5: 20})
示例2: testParseValuesWithIndexAssigment1_IgnoreUnknown
def testParseValuesWithIndexAssigment1_IgnoreUnknown(self):
"""Assignment to an index position."""
parse_dict = hparam.parse_values(
'arr[1]=10,b=5', {'arr': int}, ignore_unknown=True)
self.assertEqual(len(parse_dict), 1)
self.assertTrue(isinstance(parse_dict['arr'], dict))
self.assertDictEqual(parse_dict['arr'], {1: 10})
示例3: testParseValuesWithIndexAssigment3
def testParseValuesWithIndexAssigment3(self):
"""Assignment to index positions in multiple names."""
parse_dict = hparam.parse_values('arr[0]=10,arr[1]=20,L[5]=100,L[10]=200',
{'arr': int,
'L': int})
self.assertEqual(len(parse_dict), 2)
self.assertTrue(isinstance(parse_dict['arr'], dict))
self.assertDictEqual(parse_dict['arr'], {0: 10, 1: 20})
self.assertTrue(isinstance(parse_dict['L'], dict))
self.assertDictEqual(parse_dict['L'], {5: 100, 10: 200})
示例4: testParseValuesWithIndexAssigment4_IgnoreUnknown
def testParseValuesWithIndexAssigment4_IgnoreUnknown(self):
"""Assignment of index positions and scalars."""
parse_dict = hparam.parse_values(
'x=10,foo[0]=bar,arr[1]=20,zzz=78,y=30',
{'x': int, 'y': int, 'arr': int}, ignore_unknown=True)
self.assertEqual(len(parse_dict), 3)
self.assertTrue(isinstance(parse_dict['arr'], dict))
self.assertDictEqual(parse_dict['arr'], {1: 20})
self.assertEqual(parse_dict['x'], 10)
self.assertEqual(parse_dict['y'], 30)
示例5: testParseValuesWithIndexAssigment4
def testParseValuesWithIndexAssigment4(self):
"""Assignment of index positions and scalars."""
parse_dict = hparam.parse_values('x=10,arr[1]=20,y=30',
{'x': int,
'y': int,
'arr': int})
self.assertEqual(len(parse_dict), 3)
self.assertTrue(isinstance(parse_dict['arr'], dict))
self.assertDictEqual(parse_dict['arr'], {1: 20})
self.assertEqual(parse_dict['x'], 10)
self.assertEqual(parse_dict['y'], 30)
示例6: testWithReusedVariables
def testWithReusedVariables(self):
with self.assertRaisesRegexp(ValueError,
'Multiple assignments to variable \'x\''):
hparam.parse_values('x=1,x=1', {'x': int})
with self.assertRaisesRegexp(ValueError,
'Multiple assignments to variable \'arr\''):
hparam.parse_values('arr=[100,200],arr[0]=10', {'arr': int})
with self.assertRaisesRegexp(
ValueError, r'Multiple assignments to variable \'arr\[0\]\''):
hparam.parse_values('arr[0]=10,arr[0]=20', {'arr': int})
with self.assertRaisesRegexp(ValueError,
'Multiple assignments to variable \'arr\''):
hparam.parse_values('arr[0]=10,arr=[100]', {'arr': int})
示例7: testParseValuesWithIndexAssigment5_IgnoreUnknown
def testParseValuesWithIndexAssigment5_IgnoreUnknown(self):
"""Different variable types."""
parse_dict = hparam.parse_values(
'a[0]=5,cc=4,b[1]=true,c[2]=abc,mm=2,d[3]=3.14',
{'a': int, 'b': bool, 'c': str, 'd': float},
ignore_unknown=True)
self.assertEqual(set(parse_dict.keys()), {'a', 'b', 'c', 'd'})
self.assertTrue(isinstance(parse_dict['a'], dict))
self.assertDictEqual(parse_dict['a'], {0: 5})
self.assertTrue(isinstance(parse_dict['b'], dict))
self.assertDictEqual(parse_dict['b'], {1: True})
self.assertTrue(isinstance(parse_dict['c'], dict))
self.assertDictEqual(parse_dict['c'], {2: 'abc'})
self.assertTrue(isinstance(parse_dict['d'], dict))
self.assertDictEqual(parse_dict['d'], {3: 3.14})
示例8: testParseValuesWithBadIndexAssigment3_IgnoreUnknown
def testParseValuesWithBadIndexAssigment3_IgnoreUnknown(self):
"""Ignore type of the form name[index]."""
hparam.parse_values('arr[1]=1', {'arr[1]': int}, ignore_unknown=True)
示例9: testParseValuesWithBadIndexAssigment3
def testParseValuesWithBadIndexAssigment3(self):
"""Reject type of the form name[index]."""
with self.assertRaisesRegexp(ValueError,
'Unknown hyperparameter type for arr'):
hparam.parse_values('arr[1]=1', {'arr[1]': int})
示例10: testParseValuesWithBadIndexAssigment2_IgnoreUnknown
def testParseValuesWithBadIndexAssigment2_IgnoreUnknown(self):
"""Ignore missing type."""
hparam.parse_values('arr[1]=5', {}, ignore_unknown=True)
示例11: testParseValuesWithBadIndexAssigment2
def testParseValuesWithBadIndexAssigment2(self):
"""Reject if type missing."""
with self.assertRaisesRegexp(ValueError,
r'Unknown hyperparameter type for arr'):
hparam.parse_values('arr[1]=5', {})
示例12: testParseValuesWithBadIndexAssigment1_IgnoreUnknown
def testParseValuesWithBadIndexAssigment1_IgnoreUnknown(self):
"""Reject assignment of list to variable type."""
with self.assertRaisesRegexp(ValueError,
r'Assignment of a list to a list index.'):
hparam.parse_values(
'arr[1]=[1,2,3],c=8', {'arr': int}, ignore_unknown=True)