{"action":"created","comment":{"url":"https://api.github.com/repos/Cognexa/cxflow/pulls/comments/170236688","pull_request_review_id":98894051,"id":170236688,"diff_hunk":"@@ -0,0 +1,136 @@\n+import numpy as np\n+import os.path as path\n+\n+import itertools\n+import matplotlib\n+matplotlib.use('Agg')\n+import matplotlib.pyplot as plt\n+\n+from . import AccumulateVariables\n+from ..types import EpochData\n+from ..datasets import BaseDataset\n+\n+\n+class SaveConfusionMatrix(AccumulateVariables):\n+    \"\"\"\n+    Compute and save conufusion matrix between the predicted and expected labels.\n+\n+    .. code-block:: yaml\n+        :caption: Store confusion matrix heatmap\n+\n+        hooks:\n+          - SaveConfusionMatrix:\n+              figure_action: store\n+\n+    .. code-block:: yaml\n+        :caption: Save confusion matrix heatmap with absolute values\n+\n+        hooks:\n+          - SaveConfusionMatrix:\n+              normalize: False\n+    \"\"\"\n+\n+    FIGURE_ACTIONS = ['save', 'store']\n+    \"\"\"\n+    Possible actions to be taken with the plotted figure. \n+    It can be either saved to a file or stored in the epoch data.\n+    \"\"\"\n+\n+    def __init__(self,\n+                 output_dir: str,\n+                 dataset: BaseDataset,\n+                 annotations_name: str='annotations',\n+                 probabilities_name: str= 'probabilities',\n+                 classes_name: str=None,\n+                 figure_action: str='save',\n+                 normalize=True,\n+                 cmap: str='Blues', **kwargs):\n+        \"\"\"\n+        Create new :py:class:`SaveConfusionMatrix` hook.\n+        :param output_dir: output directory\n+        :param dataset: dataset (needed to translate predictions to strings)\n+        :param annotations_name: annotation variable name\n+        :param probabilities_name: prediction variable name\n+        :param figure_action: action to be taken with the plotted figure, one of :py:attr:`FIGURE_ACTIONS`\n+        :param normalize: False for plotting absolute values in confusion matrix, True for relative\n+        :param cmap: type of colorbar  # http://matplotlib.org/examples/color/colormaps_reference.html\n+        \"\"\"\n+        if figure_action not in SaveConfusionMatrix.FIGURE_ACTIONS:\n+            raise ValueError('Unrecognized figure action `{}`. It must be one of `{}`'.\n+                             format(figure_action, SaveConfusionMatrix.FIGURE_ACTIONS))\n+\n+        self._dataset = dataset\n+        self._output_dir = output_dir\n+        self._annotations_name = annotations_name\n+        self._probabilities_name = probabilities_name\n+        self._classes_name = classes_name\n+        self._figure_action = figure_action\n+        self._normalize = normalize\n+        self._cmap = cmap\n+\n+        super().__init__(variables=list(filter(None, [annotations_name, probabilities_name, classes_name])), **kwargs)","path":"cxflow/hooks/confusion_matrix.py","position":71,"original_position":71,"commit_id":"c3042787871dd1ae168cacc090375ee9456ade24","original_commit_id":"c3042787871dd1ae168cacc090375ee9456ade24","user":{"login":"bvavrik","id":13049337,"avatar_url":"https://avatars2.githubusercontent.com/u/13049337?v=4","gravatar_id":"","url":"https://api.github.com/users/bvavrik","html_url":"https://github.com/bvavrik","followers_url":"https://api.github.com/users/bvavrik/followers","following_url":"https://api.github.com/users/bvavrik/following{/other_user}","gists_url":"https://api.github.com/users/bvavrik/gists{/gist_id}","starred_url":"https://api.github.com/users/bvavrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvavrik/subscriptions","organizations_url":"https://api.github.com/users/bvavrik/orgs","repos_url":"https://api.github.com/users/bvavrik/repos","events_url":"https://api.github.com/users/bvavrik/events{/privacy}","received_events_url":"https://api.github.com/users/bvavrik/received_events","type":"User","site_admin":false},"body":"That `filter` is used for `classes_name` only, will be deleted after `classes_name` removal\r\n","created_at":"2018-02-23T12:12:32Z","updated_at":"2018-02-23T12:12:32Z","html_url":"https://github.com/Cognexa/cxflow/pull/207#discussion_r170236688","pull_request_url":"https://api.github.com/repos/Cognexa/cxflow/pulls/207","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/Cognexa/cxflow/pulls/comments/170236688"},"html":{"href":"https://github.com/Cognexa/cxflow/pull/207#discussion_r170236688"},"pull_request":{"href":"https://api.github.com/repos/Cognexa/cxflow/pulls/207"}},"in_reply_to_id":170232817},"pull_request":{"url":"https://api.github.com/repos/Cognexa/cxflow/pulls/207","id":170488935,"html_url":"https://github.com/Cognexa/cxflow/pull/207","diff_url":"https://github.com/Cognexa/cxflow/pull/207.diff","patch_url":"https://github.com/Cognexa/cxflow/pull/207.patch","issue_url":"https://api.github.com/repos/Cognexa/cxflow/issues/207","number":207,"state":"open","locked":false,"title":"Add confusion matrix hook","user":{"login":"bvavrik","id":13049337,"avatar_url":"https://avatars2.githubusercontent.com/u/13049337?v=4","gravatar_id":"","url":"https://api.github.com/users/bvavrik","html_url":"https://github.com/bvavrik","followers_url":"https://api.github.com/users/bvavrik/followers","following_url":"https://api.github.com/users/bvavrik/following{/other_user}","gists_url":"https://api.github.com/users/bvavrik/gists{/gist_id}","starred_url":"https://api.github.com/users/bvavrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvavrik/subscriptions","organizations_url":"https://api.github.com/users/bvavrik/orgs","repos_url":"https://api.github.com/users/bvavrik/repos","events_url":"https://api.github.com/users/bvavrik/events{/privacy}","received_events_url":"https://api.github.com/users/bvavrik/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-02-21T14:42:01Z","updated_at":"2018-02-23T12:12:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2a14244ea90030198aac1e89e313d7e243eeabd5","assignee":null,"assignees":[],"requested_reviewers":[{"login":"blazekadam","id":5741240,"avatar_url":"https://avatars1.githubusercontent.com/u/5741240?v=4","gravatar_id":"","url":"https://api.github.com/users/blazekadam","html_url":"https://github.com/blazekadam","followers_url":"https://api.github.com/users/blazekadam/followers","following_url":"https://api.github.com/users/blazekadam/following{/other_user}","gists_url":"https://api.github.com/users/blazekadam/gists{/gist_id}","starred_url":"https://api.github.com/users/blazekadam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blazekadam/subscriptions","organizations_url":"https://api.github.com/users/blazekadam/orgs","repos_url":"https://api.github.com/users/blazekadam/repos","events_url":"https://api.github.com/users/blazekadam/events{/privacy}","received_events_url":"https://api.github.com/users/blazekadam/received_events","type":"User","site_admin":false},{"login":"FloopCZ","id":6018335,"avatar_url":"https://avatars1.githubusercontent.com/u/6018335?v=4","gravatar_id":"","url":"https://api.github.com/users/FloopCZ","html_url":"https://github.com/FloopCZ","followers_url":"https://api.github.com/users/FloopCZ/followers","following_url":"https://api.github.com/users/FloopCZ/following{/other_user}","gists_url":"https://api.github.com/users/FloopCZ/gists{/gist_id}","starred_url":"https://api.github.com/users/FloopCZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FloopCZ/subscriptions","organizations_url":"https://api.github.com/users/FloopCZ/orgs","repos_url":"https://api.github.com/users/FloopCZ/repos","events_url":"https://api.github.com/users/FloopCZ/events{/privacy}","received_events_url":"https://api.github.com/users/FloopCZ/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Cognexa/cxflow/pulls/207/commits","review_comments_url":"https://api.github.com/repos/Cognexa/cxflow/pulls/207/comments","review_comment_url":"https://api.github.com/repos/Cognexa/cxflow/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Cognexa/cxflow/issues/207/comments","statuses_url":"https://api.github.com/repos/Cognexa/cxflow/statuses/c3042787871dd1ae168cacc090375ee9456ade24","head":{"label":"Cognexa:confusion_matrix_hook","ref":"confusion_matrix_hook","sha":"c3042787871dd1ae168cacc090375ee9456ade24","user":{"login":"Cognexa","id":25585336,"avatar_url":"https://avatars2.githubusercontent.com/u/25585336?v=4","gravatar_id":"","url":"https://api.github.com/users/Cognexa","html_url":"https://github.com/Cognexa","followers_url":"https://api.github.com/users/Cognexa/followers","following_url":"https://api.github.com/users/Cognexa/following{/other_user}","gists_url":"https://api.github.com/users/Cognexa/gists{/gist_id}","starred_url":"https://api.github.com/users/Cognexa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cognexa/subscriptions","organizations_url":"https://api.github.com/users/Cognexa/orgs","repos_url":"https://api.github.com/users/Cognexa/repos","events_url":"https://api.github.com/users/Cognexa/events{/privacy}","received_events_url":"https://api.github.com/users/Cognexa/received_events","type":"Organization","site_admin":false},"repo":{"id":82841836,"name":"cxflow","full_name":"Cognexa/cxflow","owner":{"login":"Cognexa","id":25585336,"avatar_url":"https://avatars2.githubusercontent.com/u/25585336?v=4","gravatar_id":"","url":"https://api.github.com/users/Cognexa","html_url":"https://github.com/Cognexa","followers_url":"https://api.github.com/users/Cognexa/followers","following_url":"https://api.github.com/users/Cognexa/following{/other_user}","gists_url":"https://api.github.com/users/Cognexa/gists{/gist_id}","starred_url":"https://api.github.com/users/Cognexa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cognexa/subscriptions","organizations_url":"https://api.github.com/users/Cognexa/orgs","repos_url":"https://api.github.com/users/Cognexa/repos","events_url":"https://api.github.com/users/Cognexa/events{/privacy}","received_events_url":"https://api.github.com/users/Cognexa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Cognexa/cxflow","description":"Lightweight framework for machine learning with focus on modularization, re-usability and rapid experimenting","fork":false,"url":"https://api.github.com/repos/Cognexa/cxflow","forks_url":"https://api.github.com/repos/Cognexa/cxflow/forks","keys_url":"https://api.github.com/repos/Cognexa/cxflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Cognexa/cxflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Cognexa/cxflow/teams","hooks_url":"https://api.github.com/repos/Cognexa/cxflow/hooks","issue_events_url":"https://api.github.com/repos/Cognexa/cxflow/issues/events{/number}","events_url":"https://api.github.com/repos/Cognexa/cxflow/events","assignees_url":"https://api.github.com/repos/Cognexa/cxflow/assignees{/user}","branches_url":"https://api.github.com/repos/Cognexa/cxflow/branches{/branch}","tags_url":"https://api.github.com/repos/Cognexa/cxflow/tags","blobs_url":"https://api.github.com/repos/Cognexa/cxflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Cognexa/cxflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Cognexa/cxflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/Cognexa/cxflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Cognexa/cxflow/statuses/{sha}","languages_url":"https://api.github.com/repos/Cognexa/cxflow/languages","stargazers_url":"https://api.github.com/repos/Cognexa/cxflow/stargazers","contributors_url":"https://api.github.com/repos/Cognexa/cxflow/contributors","subscribers_url":"https://api.github.com/repos/Cognexa/cxflow/subscribers","subscription_url":"https://api.github.com/repos/Cognexa/cxflow/subscription","commits_url":"https://api.github.com/repos/Cognexa/cxflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/Cognexa/cxflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/Cognexa/cxflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/Cognexa/cxflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/Cognexa/cxflow/contents/{+path}","compare_url":"https://api.github.com/repos/Cognexa/cxflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Cognexa/cxflow/merges","archive_url":"https://api.github.com/repos/Cognexa/cxflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Cognexa/cxflow/downloads","issues_url":"https://api.github.com/repos/Cognexa/cxflow/issues{/number}","pulls_url":"https://api.github.com/repos/Cognexa/cxflow/pulls{/number}","milestones_url":"https://api.github.com/repos/Cognexa/cxflow/milestones{/number}","notifications_url":"https://api.github.com/repos/Cognexa/cxflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Cognexa/cxflow/labels{/name}","releases_url":"https://api.github.com/repos/Cognexa/cxflow/releases{/id}","deployments_url":"https://api.github.com/repos/Cognexa/cxflow/deployments","created_at":"2017-02-22T19:01:36Z","updated_at":"2018-01-23T17:25:49Z","pushed_at":"2018-02-23T09:26:33Z","git_url":"git://github.com/Cognexa/cxflow.git","ssh_url":"git@github.com:Cognexa/cxflow.git","clone_url":"https://github.com/Cognexa/cxflow.git","svn_url":"https://github.com/Cognexa/cxflow","homepage":"https://cxflow.org","size":2237,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":9,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2,"open_issues":9,"watchers":16,"default_branch":"dev"}},"base":{"label":"Cognexa:dev","ref":"dev","sha":"528361a0e716c22aaa0e3e93cd6863a6871b33c2","user":{"login":"Cognexa","id":25585336,"avatar_url":"https://avatars2.githubusercontent.com/u/25585336?v=4","gravatar_id":"","url":"https://api.github.com/users/Cognexa","html_url":"https://github.com/Cognexa","followers_url":"https://api.github.com/users/Cognexa/followers","following_url":"https://api.github.com/users/Cognexa/following{/other_user}","gists_url":"https://api.github.com/users/Cognexa/gists{/gist_id}","starred_url":"https://api.github.com/users/Cognexa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cognexa/subscriptions","organizations_url":"https://api.github.com/users/Cognexa/orgs","repos_url":"https://api.github.com/users/Cognexa/repos","events_url":"https://api.github.com/users/Cognexa/events{/privacy}","received_events_url":"https://api.github.com/users/Cognexa/received_events","type":"Organization","site_admin":false},"repo":{"id":82841836,"name":"cxflow","full_name":"Cognexa/cxflow","owner":{"login":"Cognexa","id":25585336,"avatar_url":"https://avatars2.githubusercontent.com/u/25585336?v=4","gravatar_id":"","url":"https://api.github.com/users/Cognexa","html_url":"https://github.com/Cognexa","followers_url":"https://api.github.com/users/Cognexa/followers","following_url":"https://api.github.com/users/Cognexa/following{/other_user}","gists_url":"https://api.github.com/users/Cognexa/gists{/gist_id}","starred_url":"https://api.github.com/users/Cognexa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cognexa/subscriptions","organizations_url":"https://api.github.com/users/Cognexa/orgs","repos_url":"https://api.github.com/users/Cognexa/repos","events_url":"https://api.github.com/users/Cognexa/events{/privacy}","received_events_url":"https://api.github.com/users/Cognexa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Cognexa/cxflow","description":"Lightweight framework for machine learning with focus on modularization, re-usability and rapid experimenting","fork":false,"url":"https://api.github.com/repos/Cognexa/cxflow","forks_url":"https://api.github.com/repos/Cognexa/cxflow/forks","keys_url":"https://api.github.com/repos/Cognexa/cxflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Cognexa/cxflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Cognexa/cxflow/teams","hooks_url":"https://api.github.com/repos/Cognexa/cxflow/hooks","issue_events_url":"https://api.github.com/repos/Cognexa/cxflow/issues/events{/number}","events_url":"https://api.github.com/repos/Cognexa/cxflow/events","assignees_url":"https://api.github.com/repos/Cognexa/cxflow/assignees{/user}","branches_url":"https://api.github.com/repos/Cognexa/cxflow/branches{/branch}","tags_url":"https://api.github.com/repos/Cognexa/cxflow/tags","blobs_url":"https://api.github.com/repos/Cognexa/cxflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Cognexa/cxflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Cognexa/cxflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/Cognexa/cxflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Cognexa/cxflow/statuses/{sha}","languages_url":"https://api.github.com/repos/Cognexa/cxflow/languages","stargazers_url":"https://api.github.com/repos/Cognexa/cxflow/stargazers","contributors_url":"https://api.github.com/repos/Cognexa/cxflow/contributors","subscribers_url":"https://api.github.com/repos/Cognexa/cxflow/subscribers","subscription_url":"https://api.github.com/repos/Cognexa/cxflow/subscription","commits_url":"https://api.github.com/repos/Cognexa/cxflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/Cognexa/cxflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/Cognexa/cxflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/Cognexa/cxflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/Cognexa/cxflow/contents/{+path}","compare_url":"https://api.github.com/repos/Cognexa/cxflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Cognexa/cxflow/merges","archive_url":"https://api.github.com/repos/Cognexa/cxflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Cognexa/cxflow/downloads","issues_url":"https://api.github.com/repos/Cognexa/cxflow/issues{/number}","pulls_url":"https://api.github.com/repos/Cognexa/cxflow/pulls{/number}","milestones_url":"https://api.github.com/repos/Cognexa/cxflow/milestones{/number}","notifications_url":"https://api.github.com/repos/Cognexa/cxflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Cognexa/cxflow/labels{/name}","releases_url":"https://api.github.com/repos/Cognexa/cxflow/releases{/id}","deployments_url":"https://api.github.com/repos/Cognexa/cxflow/deployments","created_at":"2017-02-22T19:01:36Z","updated_at":"2018-01-23T17:25:49Z","pushed_at":"2018-02-23T09:26:33Z","git_url":"git://github.com/Cognexa/cxflow.git","ssh_url":"git@github.com:Cognexa/cxflow.git","clone_url":"https://github.com/Cognexa/cxflow.git","svn_url":"https://github.com/Cognexa/cxflow","homepage":"https://cxflow.org","size":2237,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":9,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2,"open_issues":9,"watchers":16,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Cognexa/cxflow/pulls/207"},"html":{"href":"https://github.com/Cognexa/cxflow/pull/207"},"issue":{"href":"https://api.github.com/repos/Cognexa/cxflow/issues/207"},"comments":{"href":"https://api.github.com/repos/Cognexa/cxflow/issues/207/comments"},"review_comments":{"href":"https://api.github.com/repos/Cognexa/cxflow/pulls/207/comments"},"review_comment":{"href":"https://api.github.com/repos/Cognexa/cxflow/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Cognexa/cxflow/pulls/207/commits"},"statuses":{"href":"https://api.github.com/repos/Cognexa/cxflow/statuses/c3042787871dd1ae168cacc090375ee9456ade24"}},"author_association":"NONE"}}
{"actor":{"display_login":"bvavrik"}}