{
  "id": 130539,
  "title": "Dynamic visualization of pytorch loss and metrics with Visdom ",
  "url": "/competitions/bengaliai-cv19/discussion/130539",
  "author_name": "Orion",
  "post_date": "2020-02-14T18:46:46.794000",
  "votes": 6,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I'm using visdom to monitor my model performance in local training. It's really brief and useful. So I want to introduce it to you.</p>\n\n<p>Visdom Github : <a href=\"https://github.com/facebookresearch/visdom\">https://github.com/facebookresearch/visdom</a></p>\n\n<p>You can use following code to visualize your loss and metric:</p>\n\n<p>```\nfrom visdom import Visdom\nimport numpy as np</p>\n\n<p>viz = Visdom()</p>\n\n<h1>create and initialize</h1>\n\n<p>viz.line([[0., 0.]], [0], win='train', opts=dict(title='loss&amp;acc', legend=['loss', 'acc']))</p>\n\n<p>for global_steps in range(10):</p>\n\n<pre><code># just for example\ntrain_loss = 0.1 * np.random.randn() + 1\ntrain_acc = 0.1 * np.random.randn() + 0.5\n\n# update the window\nviz.line([[train_loss, train_acc]], [global_steps], win='train', update='append')\n\ntime.sleep(0.5)\n</code></pre>\n\n<p>```</p>\n\n<p>Result will be  like this: </p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F1818e1ff02e0e0f7dc4a89d2a65484d3%2F1449510-20190608211703759-548259221.gif?generation=1581705260230079&amp;alt=media\" alt=\"\"></p>\n\n<p>And even you can visualize your training images using following codes:</p>\n\n<p><code>viz.image(torchvision.utils.make_grid(next(iter(train_dataloader))[0]), win='train-image')</code></p>\n\n<p>Final results:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F856faaebb1b9f1a18617b09957eccbc8%2FTIM20200215023939.png?generation=1581705611727591&amp;alt=media\" alt=\"\"></p>",
  "messages": [
    {
      "id": 1504265,
      "postDate": "2021-09-06T08:11:17.493Z",
      "content": "<p>Hey, I tried to recreate this snippet on kaggle and ran into a connection refused problem. Did you encounter this too? If so how did you rectify it? Thanks!</p>",
      "rawMarkdown": "Hey, I tried to recreate this snippet on kaggle and ran into a connection refused problem. Did you encounter this too? If so how did you rectify it? Thanks!",
      "votes": 1,
      "replies": [
        {
          "id": 2498040,
          "postDate": "2023-10-25T05:22:22.973Z",
          "rawMarkdown": "",
          "isDeleted": true
        }
      ]
    },
    {
      "id": 746212,
      "postDate": "2020-02-14T18:46:46.793Z",
      "content": "<p>I'm using visdom to monitor my model performance in local training. It's really brief and useful. So I want to introduce it to you.</p>\n\n<p>Visdom Github : <a href=\"https://github.com/facebookresearch/visdom\">https://github.com/facebookresearch/visdom</a></p>\n\n<p>You can use following code to visualize your loss and metric:</p>\n\n<p>```\nfrom visdom import Visdom\nimport numpy as np</p>\n\n<p>viz = Visdom()</p>\n\n<h1>create and initialize</h1>\n\n<p>viz.line([[0., 0.]], [0], win='train', opts=dict(title='loss&amp;acc', legend=['loss', 'acc']))</p>\n\n<p>for global_steps in range(10):</p>\n\n<pre><code># just for example\ntrain_loss = 0.1 * np.random.randn() + 1\ntrain_acc = 0.1 * np.random.randn() + 0.5\n\n# update the window\nviz.line([[train_loss, train_acc]], [global_steps], win='train', update='append')\n\ntime.sleep(0.5)\n</code></pre>\n\n<p>```</p>\n\n<p>Result will be  like this: </p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F1818e1ff02e0e0f7dc4a89d2a65484d3%2F1449510-20190608211703759-548259221.gif?generation=1581705260230079&amp;alt=media\" alt=\"\"></p>\n\n<p>And even you can visualize your training images using following codes:</p>\n\n<p><code>viz.image(torchvision.utils.make_grid(next(iter(train_dataloader))[0]), win='train-image')</code></p>\n\n<p>Final results:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F856faaebb1b9f1a18617b09957eccbc8%2FTIM20200215023939.png?generation=1581705611727591&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "I'm using visdom to monitor my model performance in local training. It's really brief and useful. So I want to introduce it to you.\n\nVisdom Github : [https://github.com/facebookresearch/visdom](https://github.com/facebookresearch/visdom)\n\nYou can use following code to visualize your loss and metric:\n\n```\nfrom visdom import Visdom\nimport numpy as np\n\nviz = Visdom()\n# create and initialize\nviz.line([[0., 0.]], [0], win='train', opts=dict(title='loss&amp;acc', legend=['loss', 'acc']))\n\nfor global_steps in range(10):\n\n    # just for example\n    train_loss = 0.1 * np.random.randn() + 1\n    train_acc = 0.1 * np.random.randn() + 0.5\n\n    # update the window\n    viz.line([[train_loss, train_acc]], [global_steps], win='train', update='append')\n\n    time.sleep(0.5)\n\n```\n\nResult will be  like this: \n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F1818e1ff02e0e0f7dc4a89d2a65484d3%2F1449510-20190608211703759-548259221.gif?generation=1581705260230079&amp;alt=media)\n\nAnd even you can visualize your training images using following codes:\n\n`viz.image(torchvision.utils.make_grid(next(iter(train_dataloader))[0]), win='train-image')`\n\n\nFinal results:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F856faaebb1b9f1a18617b09957eccbc8%2FTIM20200215023939.png?generation=1581705611727591&amp;alt=media)\n",
      "votes": 6
    },
    {
      "id": 746977,
      "postDate": "2020-02-15T19:57:51.657Z",
      "content": "<p>Cool! I always want something like this. Thanks for sharing!</p>",
      "rawMarkdown": "Cool! I always want something like this. Thanks for sharing!"
    }
  ],
  "comments": [
    {
      "id": 1504265,
      "author_name": "Chinmay Badjatya",
      "author_url": "",
      "post_date": "2021-09-06T08:11:17.493000",
      "content": "<p>Hey, I tried to recreate this snippet on kaggle and ran into a connection refused problem. Did you encounter this too? If so how did you rectify it? Thanks!</p>",
      "votes": 1,
      "replies": [
        {
          "id": 2498040,
          "author_name": "",
          "author_url": "",
          "post_date": "2023-10-25T05:22:22.973000",
          "content": "",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 746977,
      "author_name": "Helen",
      "author_url": "",
      "post_date": "2020-02-15T19:57:51.657000",
      "content": "<p>Cool! I always want something like this. Thanks for sharing!</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1504265": "Hey, I tried to recreate this snippet on kaggle and ran into a connection refused problem. Did you encounter this too? If so how did you rectify it? Thanks!",
    "746212": "I'm using visdom to monitor my model performance in local training. It's really brief and useful. So I want to introduce it to you.\n\nVisdom Github : [https://github.com/facebookresearch/visdom](https://github.com/facebookresearch/visdom)\n\nYou can use following code to visualize your loss and metric:\n\n```\nfrom visdom import Visdom\nimport numpy as np\n\nviz = Visdom()\n# create and initialize\nviz.line([[0., 0.]], [0], win='train', opts=dict(title='loss&amp;acc', legend=['loss', 'acc']))\n\nfor global_steps in range(10):\n\n    # just for example\n    train_loss = 0.1 * np.random.randn() + 1\n    train_acc = 0.1 * np.random.randn() + 0.5\n\n    # update the window\n    viz.line([[train_loss, train_acc]], [global_steps], win='train', update='append')\n\n    time.sleep(0.5)\n\n```\n\nResult will be  like this: \n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F1818e1ff02e0e0f7dc4a89d2a65484d3%2F1449510-20190608211703759-548259221.gif?generation=1581705260230079&amp;alt=media)\n\nAnd even you can visualize your training images using following codes:\n\n`viz.image(torchvision.utils.make_grid(next(iter(train_dataloader))[0]), win='train-image')`\n\n\nFinal results:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3818110%2F856faaebb1b9f1a18617b09957eccbc8%2FTIM20200215023939.png?generation=1581705611727591&amp;alt=media)\n",
    "746977": "Cool! I always want something like this. Thanks for sharing!"
  }
}