Skip to content

Instantly share code, notes, and snippets.

@philopon
Created April 23, 2019 13:57
Show Gist options
  • Save philopon/9377273a9544775eb46301e880cd9148 to your computer and use it in GitHub Desktop.
Save philopon/9377273a9544775eb46301e880cd9148 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Untitled2.ipynb",
"version": "0.3.2",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"metadata": {
"id": "si6zzdrPbINo",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"import torch\n",
"import cv2"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "37-X1dqVbT65",
"colab_type": "code",
"outputId": "33a286a4-24ba-4515-c87c-d0fc909f46b9",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 54
}
},
"cell_type": "code",
"source": [
"print(f\"pytorch version: {torch.__version__}\")\n",
"print(f\"cv2 version: {cv2.__version__}\")"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"pytorch version: 1.0.1.post2\n",
"cv2 version: 3.4.3\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "OYxjt4nYbMe8",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 54
},
"outputId": "8e23e655-9499-4f16-b149-61e84a175aa6"
},
"cell_type": "code",
"source": [
"x = torch.tensor([[[[64, 32], [64, 32]]]], dtype=torch.float32)\n",
"x"
],
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"tensor([[[[64., 32.],\n",
" [64., 32.]]]])"
]
},
"metadata": {
"tags": []
},
"execution_count": 3
}
]
},
{
"metadata": {
"id": "k2JeeL49eYgi",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"size = (4, 4)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "p1c63xCObSXM",
"colab_type": "code",
"outputId": "e3e1025d-4700-4e02-e8a3-8d703bc2337d",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 147
}
},
"cell_type": "code",
"source": [
"torch.nn.functional.interpolate(x, size=size, mode='bilinear')"
],
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": [
"/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:2423: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
" \"See the documentation of nn.Upsample for details.\".format(mode))\n"
],
"name": "stderr"
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"tensor([[[[64., 56., 40., 32.],\n",
" [64., 56., 40., 32.],\n",
" [64., 56., 40., 32.],\n",
" [64., 56., 40., 32.]]]])"
]
},
"metadata": {
"tags": []
},
"execution_count": 5
}
]
},
{
"metadata": {
"id": "0Np82pf1djAD",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 90
},
"outputId": "fdc51180-9571-47b8-f5a1-b01bcd5619b2"
},
"cell_type": "code",
"source": [
"cv2.resize(x.numpy()[0, 0], size)"
],
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[64., 56., 40., 32.],\n",
" [64., 56., 40., 32.],\n",
" [64., 56., 40., 32.],\n",
" [64., 56., 40., 32.]], dtype=float32)"
]
},
"metadata": {
"tags": []
},
"execution_count": 6
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment