def enumerate_visual_onnx_representation_into_rst(sub, fLOG=noLOG): """ Returns content for pages such as :ref:`l-skl2onnx-linear_model`. """ logger = getLogger('skl2onnx') logger.disabled = True templ = Template(visual_rst_template()) done = set() subsets = [_['name'] for _ in sklearn_operators(sub)] subsets.sort() for row in enumerate_validated_operator_opsets( verbose=0, debug=None, fLOG=fLOG, opset_min=get_opset_number_from_onnx(), store_models=True, models=subsets): if 'ONNX' not in row: continue name = row['name'] scenario = row['scenario'] problem = row['problem'] model = row['MODEL'] method = row['method_name'] title = " - ".join([name, problem, scenario]) if title in done: continue done.add(title) link = "-".join([name, problem, scenario]) oinf = OnnxInference(row['ONNX'], skip_run=True) dot = oinf.to_dot() res = templ.render(dot=dot, model=repr(model), method=method, kind=problem, title=title, indent=indent, len=len, link=link) yield res
def test_write_documentation_converters(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") subs = [] for sub in sorted(sklearn__all__): models = sklearn_operators(sub) if len(models) > 0: rows = [] for row in enumerate_visual_onnx_representation_into_rst(sub): self.assertIn("digraph", row) rows.append(row) if len(rows) == 0: continue rows = [ ".. _l-skl2onnx-%s:" % sub, "", "=" * len(sub), sub, "=" * len(sub), "", ".. contents::", " :local:", "" ] + rows rows.append('') subs.append(sub) fLOG("subfolder '{}' - {} scenarios.".format(sub, len(models))) self.assertGreater(len(subs), 2)
def test_sklearn_operators(self): res = sklearn_operators() self.assertGreater(len(res), 1) self.assertEqual(len(res[0]), 4) short = ['IsotonicRegression'] for model in res: if model['name'] not in short: continue prob = find_suitable_problem(model['cl']) self.assertNotEmpty(prob) if model['name'] == 'IsotonicRegression': self.assertEqual(prob, ['~num+y-tr-1d', '~b-reg-1d']) names = set(_['name'] for _ in res) self.assertIn('Perceptron', names) self.assertIn('TfidfVectorizer', names) ra = { 'BaseEnsemble', 'NearestNeighbors', 'AgglomerativeClustering', 'DBSCAN', 'OPTICS', 'SpectralClustering', 'SpectralBiclustering', 'SpectralCoclustering' } for model in res: if model['name'] in ra: self.assertRaise( lambda m=model: find_suitable_problem(m['cl']), RuntimeError) continue prob = find_suitable_problem(model['cl']) self.assertNotEmpty(prob) if model['name'] == 'IsotonicRegression': self.assertEqual(prob, ['~num+y-tr-1d', '~b-reg-1d']) elif model['name'] == 'NearestCentroid': self.assertEqual(prob, ['~b-cl-nop', '~b-cl-nop-64']) self.assertIsInstance(prob, list)
def test_sklearn_operators(self): res = sklearn_operators() self.assertGreater(len(res), 1) self.assertEqual(len(res[0]), 4)