replace yolo notebook with a link
This commit is contained in:
parent
0fe8d22c82
commit
3f2e4397c8
266
example/basic/.ipynb_checkpoints/gotch_basic-checkpoint.ipynb
Normal file
266
example/basic/.ipynb_checkpoints/gotch_basic-checkpoint.ipynb
Normal file
|
@ -0,0 +1,266 @@
|
||||||
|
{
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 0,
|
||||||
|
"metadata": {
|
||||||
|
"accelerator": "GPU",
|
||||||
|
"colab": {
|
||||||
|
"name": "gotch-basic.ipynb",
|
||||||
|
"provenance": [],
|
||||||
|
"collapsed_sections": [
|
||||||
|
"fsitX3NbLbTB",
|
||||||
|
"l6aOKEMarRNH"
|
||||||
|
],
|
||||||
|
"toc_visible": true,
|
||||||
|
"include_colab_link": true
|
||||||
|
},
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Go",
|
||||||
|
"name": "gophernotes"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "view-in-github",
|
||||||
|
"colab_type": "text"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"<a href=\"https://colab.research.google.com/github/sugarme/gotch/blob/master/gotch_basic.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "dkq9izrfMXPV"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"# GoTch (Pytorch C++ APIs Go Binding) - Basic Tensor\n",
|
||||||
|
"\n",
|
||||||
|
"This notebook using\n",
|
||||||
|
"\n",
|
||||||
|
"1. [GoTch - Pytorch C++ APIs Go bindind](https://github.com/sugarme/gotch)\n",
|
||||||
|
"2. [GopherNotes - Jupyter Notebook Go kernel](https://github.com/gopherdata/gophernotes)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "fsitX3NbLbTB"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Install Go kernel - GopherNotes\n",
|
||||||
|
"\n",
|
||||||
|
"*NOTE: refresh/reload (browser) after this step.*"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"metadata": {
|
||||||
|
"id": "caT1iMfshw62",
|
||||||
|
"outputId": "7a00b47e-a949-4998-9dc5-bdebaab0cb8d",
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"# run this cell first time using python runtime\n",
|
||||||
|
"!add-apt-repository ppa:longsleep/golang-backports -y > /dev/null\n",
|
||||||
|
"!apt update > /dev/null \n",
|
||||||
|
"!apt install golang-go > /dev/null\n",
|
||||||
|
"%env GOPATH=/root/go\n",
|
||||||
|
"!go get -u github.com/gopherdata/gophernotes\n",
|
||||||
|
"!cp ~/go/bin/gophernotes /usr/bin/\n",
|
||||||
|
"!mkdir /usr/local/share/jupyter/kernels/gophernotes\n",
|
||||||
|
"!cp ~/go/src/github.com/gopherdata/gophernotes/kernel/* \\\n",
|
||||||
|
" /usr/local/share/jupyter/kernels/gophernotes\n",
|
||||||
|
"# then refresh (browser), it will now use gophernotes. Skip to golang in later cells"
|
||||||
|
],
|
||||||
|
"execution_count": null,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\n",
|
||||||
|
"WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
|
||||||
|
"\n",
|
||||||
|
"env: GOPATH=/root/go\n"
|
||||||
|
],
|
||||||
|
"name": "stdout"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "l6aOKEMarRNH"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Install Pytorch C++ APIs and Go binding - GoTch\n",
|
||||||
|
"\n",
|
||||||
|
"NOTE: `ldconfig` (GLIBC) current version 2.27 is currently broken when linking Libtorch library\n",
|
||||||
|
"\n",
|
||||||
|
"see issue: https://discuss.pytorch.org/libtorch-c-so-files-truncated-error-when-ldconfig/46404/6\n",
|
||||||
|
"\n",
|
||||||
|
"Google Colab default settings:\n",
|
||||||
|
"```bash\n",
|
||||||
|
"LD_LIBRARY_PATH=/usr/lib64-nvidia\n",
|
||||||
|
"LIBRARY_PATH=/usr/local/cuda/lib64/stubs\n",
|
||||||
|
"```\n",
|
||||||
|
"We copy directly `libtorch/lib` to those paths as a hacky way. "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"metadata": {
|
||||||
|
"id": "0N_jGbVft2Y7",
|
||||||
|
"outputId": "3ba03769-5bb0-4026-f8dc-c1929f4b88f2",
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"$wget -q --show-progress --progress=bar:force:noscroll -O /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip https://download.pytorch.org/libtorch/cu101/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip\n",
|
||||||
|
"$unzip -qq /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip -d /usr/local\n",
|
||||||
|
"$unzip -qq -j /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip libtorch/lib/* -d /usr/lib64-nvidia/\n",
|
||||||
|
"$unzip -qq -j /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip libtorch/lib/* -d /usr/local/cuda/lib64/stubs/"
|
||||||
|
],
|
||||||
|
"execution_count": 1,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"/tmp/libtorch-cxx11 99%[==================> ] 758.53M 68.1MB/s eta 0s "
|
||||||
|
],
|
||||||
|
"name": "stderr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"metadata": {
|
||||||
|
"id": "dVo3An-pGzFE"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"import(\"os\")\n",
|
||||||
|
"os.Setenv(\"CPATH\", \"usr/local/libtorch/lib:/usr/local/libtorch/include:/usr/local/libtorch/include/torch/csrc/api/include\")"
|
||||||
|
],
|
||||||
|
"execution_count": 2,
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"metadata": {
|
||||||
|
"id": "x_9y6CpZGlPJ",
|
||||||
|
"outputId": "465bc1e8-fcbc-44d5-cf5f-0ed8e61bc7b9",
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"$rm -f -- go.mod\n",
|
||||||
|
"$go mod init github.com/sugarme/playgo\n",
|
||||||
|
"$go get github.com/sugarme/gotch@v0.3.2"
|
||||||
|
],
|
||||||
|
"execution_count": 3,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"go: creating new go.mod: module github.com/sugarme/playgo\n",
|
||||||
|
"go: downloading github.com/sugarme/gotch v0.3.2\n"
|
||||||
|
],
|
||||||
|
"name": "stderr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"metadata": {
|
||||||
|
"id": "0obqcV4KW013"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"import(\n",
|
||||||
|
" \"fmt\"\n",
|
||||||
|
"\n",
|
||||||
|
" \"github.com/sugarme/gotch\"\n",
|
||||||
|
" ts \"github.com/sugarme/gotch/tensor\"\n",
|
||||||
|
") "
|
||||||
|
],
|
||||||
|
"execution_count": null,
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "9fL6QTwbT7kX"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Basic Tensor Operations"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"metadata": {
|
||||||
|
"id": "YkLmNrswJHYY",
|
||||||
|
"outputId": "1b4c7ac8-17a3-4f66-b295-e3cd3d8ac669",
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"device := gotch.NewCuda().CudaIfAvailable()\n",
|
||||||
|
"ts1, err := ts.Rand([]int64{3, 4, 5}, gotch.Double, device)\n",
|
||||||
|
"if err != nil {fmt.Print(err)}\n",
|
||||||
|
"ts2, err := ts.Ones([]int64{5, 3}, gotch.Double, device)\n",
|
||||||
|
"if err != nil { fmt.Print(err)}\n",
|
||||||
|
"\n",
|
||||||
|
"mul, err := ts1.Matmul(ts2, false)\n",
|
||||||
|
"if err != nil { fmt.Print(err)}\n",
|
||||||
|
"fmt.Printf(\"%.3f\", mul)"
|
||||||
|
],
|
||||||
|
"execution_count": 4,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"(1,.,.) =\n",
|
||||||
|
"1.372 1.372 1.372 \n",
|
||||||
|
"2.774 2.774 2.774 \n",
|
||||||
|
"4.150 4.150 4.150 \n",
|
||||||
|
"2.442 2.442 2.442 \n",
|
||||||
|
"\n",
|
||||||
|
"(2,.,.) =\n",
|
||||||
|
"1.935 1.935 1.935 \n",
|
||||||
|
"2.622 2.622 2.622 \n",
|
||||||
|
"2.797 2.797 2.797 \n",
|
||||||
|
"2.602 2.602 2.602 \n",
|
||||||
|
"\n",
|
||||||
|
"(3,.,.) =\n",
|
||||||
|
"2.419 2.419 2.419 \n",
|
||||||
|
"1.901 1.901 1.901 \n",
|
||||||
|
"2.795 2.795 2.795 \n",
|
||||||
|
"2.387 2.387 2.387 \n",
|
||||||
|
"\n"
|
||||||
|
],
|
||||||
|
"name": "stdout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"output_type": "execute_result",
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"297 <nil>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"tags": []
|
||||||
|
},
|
||||||
|
"execution_count": 4
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,266 +1,276 @@
|
||||||
{
|
{
|
||||||
"nbformat": 4,
|
"cells": [
|
||||||
"nbformat_minor": 0,
|
{
|
||||||
"metadata": {
|
"cell_type": "markdown",
|
||||||
"accelerator": "GPU",
|
"metadata": {
|
||||||
"colab": {
|
"colab_type": "text",
|
||||||
"name": "gotch-basic.ipynb",
|
"id": "view-in-github"
|
||||||
"provenance": [],
|
},
|
||||||
"collapsed_sections": [
|
"source": [
|
||||||
"fsitX3NbLbTB",
|
"<a href=\"https://colab.research.google.com/github/sugarme/gotch/blob/master/gotch_basic.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
||||||
"l6aOKEMarRNH"
|
]
|
||||||
],
|
|
||||||
"toc_visible": true,
|
|
||||||
"include_colab_link": true
|
|
||||||
},
|
|
||||||
"kernelspec": {
|
|
||||||
"display_name": "Go",
|
|
||||||
"name": "gophernotes"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"cells": [
|
{
|
||||||
{
|
"cell_type": "markdown",
|
||||||
"cell_type": "markdown",
|
"metadata": {
|
||||||
"metadata": {
|
"id": "dkq9izrfMXPV"
|
||||||
"id": "view-in-github",
|
},
|
||||||
"colab_type": "text"
|
"source": [
|
||||||
},
|
"# GoTch (Pytorch C++ APIs Go Binding) - Basic Tensor\n",
|
||||||
"source": [
|
"\n",
|
||||||
"<a href=\"https://colab.research.google.com/github/sugarme/gotch/blob/master/gotch_basic.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
"This notebook using\n",
|
||||||
]
|
"\n",
|
||||||
|
"1. [GoTch - Pytorch C++ APIs Go bindind](https://github.com/sugarme/gotch)\n",
|
||||||
|
"2. [GopherNotes - Jupyter Notebook Go kernel](https://github.com/gopherdata/gophernotes)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "fsitX3NbLbTB"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Install Go kernel - GopherNotes\n",
|
||||||
|
"\n",
|
||||||
|
"*NOTE: refresh/reload (browser) after this step.*"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
},
|
},
|
||||||
|
"id": "caT1iMfshw62",
|
||||||
|
"outputId": "7a00b47e-a949-4998-9dc5-bdebaab0cb8d"
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"name": "stdout",
|
||||||
"metadata": {
|
"output_type": "stream",
|
||||||
"id": "dkq9izrfMXPV"
|
"text": [
|
||||||
},
|
"\n",
|
||||||
"source": [
|
"WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
|
||||||
"# GoTch (Pytorch C++ APIs Go Binding) - Basic Tensor\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This notebook using\n",
|
"WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"1. [GoTch - Pytorch C++ APIs Go bindind](https://github.com/sugarme/gotch)\n",
|
"env: GOPATH=/root/go\n"
|
||||||
"2. [GopherNotes - Jupyter Notebook Go kernel](https://github.com/gopherdata/gophernotes)"
|
]
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {
|
|
||||||
"id": "fsitX3NbLbTB"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"## Install Go kernel - GopherNotes\n",
|
|
||||||
"\n",
|
|
||||||
"*NOTE: refresh/reload (browser) after this step.*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"metadata": {
|
|
||||||
"id": "caT1iMfshw62",
|
|
||||||
"outputId": "7a00b47e-a949-4998-9dc5-bdebaab0cb8d",
|
|
||||||
"colab": {
|
|
||||||
"base_uri": "https://localhost:8080/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"# run this cell first time using python runtime\n",
|
|
||||||
"!add-apt-repository ppa:longsleep/golang-backports -y > /dev/null\n",
|
|
||||||
"!apt update > /dev/null \n",
|
|
||||||
"!apt install golang-go > /dev/null\n",
|
|
||||||
"%env GOPATH=/root/go\n",
|
|
||||||
"!go get -u github.com/gopherdata/gophernotes\n",
|
|
||||||
"!cp ~/go/bin/gophernotes /usr/bin/\n",
|
|
||||||
"!mkdir /usr/local/share/jupyter/kernels/gophernotes\n",
|
|
||||||
"!cp ~/go/src/github.com/gopherdata/gophernotes/kernel/* \\\n",
|
|
||||||
" /usr/local/share/jupyter/kernels/gophernotes\n",
|
|
||||||
"# then refresh (browser), it will now use gophernotes. Skip to golang in later cells"
|
|
||||||
],
|
|
||||||
"execution_count": null,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"\n",
|
|
||||||
"WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
|
|
||||||
"\n",
|
|
||||||
"env: GOPATH=/root/go\n"
|
|
||||||
],
|
|
||||||
"name": "stdout"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {
|
|
||||||
"id": "l6aOKEMarRNH"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"## Install Pytorch C++ APIs and Go binding - GoTch\n",
|
|
||||||
"\n",
|
|
||||||
"NOTE: `ldconfig` (GLIBC) current version 2.27 is currently broken when linking Libtorch library\n",
|
|
||||||
"\n",
|
|
||||||
"see issue: https://discuss.pytorch.org/libtorch-c-so-files-truncated-error-when-ldconfig/46404/6\n",
|
|
||||||
"\n",
|
|
||||||
"Google Colab default settings:\n",
|
|
||||||
"```bash\n",
|
|
||||||
"LD_LIBRARY_PATH=/usr/lib64-nvidia\n",
|
|
||||||
"LIBRARY_PATH=/usr/local/cuda/lib64/stubs\n",
|
|
||||||
"```\n",
|
|
||||||
"We copy directly `libtorch/lib` to those paths as a hacky way. "
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"metadata": {
|
|
||||||
"id": "0N_jGbVft2Y7",
|
|
||||||
"outputId": "3ba03769-5bb0-4026-f8dc-c1929f4b88f2",
|
|
||||||
"colab": {
|
|
||||||
"base_uri": "https://localhost:8080/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"$wget -q --show-progress --progress=bar:force:noscroll -O /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip https://download.pytorch.org/libtorch/cu101/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip\n",
|
|
||||||
"$unzip -qq /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip -d /usr/local\n",
|
|
||||||
"$unzip -qq -j /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip libtorch/lib/* -d /usr/lib64-nvidia/\n",
|
|
||||||
"$unzip -qq -j /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip libtorch/lib/* -d /usr/local/cuda/lib64/stubs/"
|
|
||||||
],
|
|
||||||
"execution_count": 1,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"/tmp/libtorch-cxx11 99%[==================> ] 758.53M 68.1MB/s eta 0s "
|
|
||||||
],
|
|
||||||
"name": "stderr"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"metadata": {
|
|
||||||
"id": "dVo3An-pGzFE"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"import(\"os\")\n",
|
|
||||||
"os.Setenv(\"CPATH\", \"usr/local/libtorch/lib:/usr/local/libtorch/include:/usr/local/libtorch/include/torch/csrc/api/include\")"
|
|
||||||
],
|
|
||||||
"execution_count": 2,
|
|
||||||
"outputs": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"metadata": {
|
|
||||||
"id": "x_9y6CpZGlPJ",
|
|
||||||
"outputId": "465bc1e8-fcbc-44d5-cf5f-0ed8e61bc7b9",
|
|
||||||
"colab": {
|
|
||||||
"base_uri": "https://localhost:8080/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"$rm -f -- go.mod\n",
|
|
||||||
"$go mod init github.com/sugarme/playgo\n",
|
|
||||||
"$go get github.com/sugarme/gotch@v0.3.2"
|
|
||||||
],
|
|
||||||
"execution_count": 3,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"go: creating new go.mod: module github.com/sugarme/playgo\n",
|
|
||||||
"go: downloading github.com/sugarme/gotch v0.3.2\n"
|
|
||||||
],
|
|
||||||
"name": "stderr"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"metadata": {
|
|
||||||
"id": "0obqcV4KW013"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"import(\n",
|
|
||||||
" \"fmt\"\n",
|
|
||||||
"\n",
|
|
||||||
" \"github.com/sugarme/gotch\"\n",
|
|
||||||
" ts \"github.com/sugarme/gotch/tensor\"\n",
|
|
||||||
") "
|
|
||||||
],
|
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {
|
|
||||||
"id": "9fL6QTwbT7kX"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"## Basic Tensor Operations"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"metadata": {
|
|
||||||
"id": "YkLmNrswJHYY",
|
|
||||||
"outputId": "1b4c7ac8-17a3-4f66-b295-e3cd3d8ac669",
|
|
||||||
"colab": {
|
|
||||||
"base_uri": "https://localhost:8080/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"device := gotch.NewCuda().CudaIfAvailable()\n",
|
|
||||||
"ts1, err := ts.Rand([]int64{3, 4, 5}, gotch.Double, device)\n",
|
|
||||||
"if err != nil {fmt.Print(err)}\n",
|
|
||||||
"ts2, err := ts.Ones([]int64{5, 3}, gotch.Double, device)\n",
|
|
||||||
"if err != nil { fmt.Print(err)}\n",
|
|
||||||
"\n",
|
|
||||||
"mul, err := ts1.Matmul(ts2, false)\n",
|
|
||||||
"if err != nil { fmt.Print(err)}\n",
|
|
||||||
"fmt.Printf(\"%.3f\", mul)"
|
|
||||||
],
|
|
||||||
"execution_count": 4,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"(1,.,.) =\n",
|
|
||||||
"1.372 1.372 1.372 \n",
|
|
||||||
"2.774 2.774 2.774 \n",
|
|
||||||
"4.150 4.150 4.150 \n",
|
|
||||||
"2.442 2.442 2.442 \n",
|
|
||||||
"\n",
|
|
||||||
"(2,.,.) =\n",
|
|
||||||
"1.935 1.935 1.935 \n",
|
|
||||||
"2.622 2.622 2.622 \n",
|
|
||||||
"2.797 2.797 2.797 \n",
|
|
||||||
"2.602 2.602 2.602 \n",
|
|
||||||
"\n",
|
|
||||||
"(3,.,.) =\n",
|
|
||||||
"2.419 2.419 2.419 \n",
|
|
||||||
"1.901 1.901 1.901 \n",
|
|
||||||
"2.795 2.795 2.795 \n",
|
|
||||||
"2.387 2.387 2.387 \n",
|
|
||||||
"\n"
|
|
||||||
],
|
|
||||||
"name": "stdout"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"output_type": "execute_result",
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"297 <nil>"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {
|
|
||||||
"tags": []
|
|
||||||
},
|
|
||||||
"execution_count": 4
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
}
|
"source": [
|
||||||
|
"# run this cell first time using python runtime\n",
|
||||||
|
"!add-apt-repository ppa:longsleep/golang-backports -y > /dev/null\n",
|
||||||
|
"!apt update > /dev/null \n",
|
||||||
|
"!apt install golang-go > /dev/null\n",
|
||||||
|
"%env GOPATH=/root/go\n",
|
||||||
|
"!go get -u github.com/gopherdata/gophernotes\n",
|
||||||
|
"!cp ~/go/bin/gophernotes /usr/bin/\n",
|
||||||
|
"!mkdir /usr/local/share/jupyter/kernels/gophernotes\n",
|
||||||
|
"!cp ~/go/src/github.com/gopherdata/gophernotes/kernel/* \\\n",
|
||||||
|
" /usr/local/share/jupyter/kernels/gophernotes\n",
|
||||||
|
"# then refresh (browser), it will now use gophernotes. Skip to golang in later cells"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "l6aOKEMarRNH"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Install Pytorch C++ APIs and Go binding - GoTch\n",
|
||||||
|
"\n",
|
||||||
|
"NOTE: `ldconfig` (GLIBC) current version 2.27 is currently broken when linking Libtorch library\n",
|
||||||
|
"\n",
|
||||||
|
"see issue: https://discuss.pytorch.org/libtorch-c-so-files-truncated-error-when-ldconfig/46404/6\n",
|
||||||
|
"\n",
|
||||||
|
"Google Colab default settings:\n",
|
||||||
|
"```bash\n",
|
||||||
|
"LD_LIBRARY_PATH=/usr/lib64-nvidia\n",
|
||||||
|
"LIBRARY_PATH=/usr/local/cuda/lib64/stubs\n",
|
||||||
|
"```\n",
|
||||||
|
"We copy directly `libtorch/lib` to those paths as a hacky way. "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
|
},
|
||||||
|
"id": "0N_jGbVft2Y7",
|
||||||
|
"outputId": "3ba03769-5bb0-4026-f8dc-c1929f4b88f2"
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"/tmp/libtorch-cxx11 99%[==================> ] 758.53M 68.1MB/s eta 0s "
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"$wget -q --show-progress --progress=bar:force:noscroll -O /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip https://download.pytorch.org/libtorch/cu101/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip\n",
|
||||||
|
"$unzip -qq /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip -d /usr/local\n",
|
||||||
|
"$unzip -qq -j /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip libtorch/lib/* -d /usr/lib64-nvidia/\n",
|
||||||
|
"$unzip -qq -j /tmp/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcu101.zip libtorch/lib/* -d /usr/local/cuda/lib64/stubs/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {
|
||||||
|
"id": "dVo3An-pGzFE"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import(\"os\")\n",
|
||||||
|
"os.Setenv(\"CPATH\", \"usr/local/libtorch/lib:/usr/local/libtorch/include:/usr/local/libtorch/include/torch/csrc/api/include\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
|
},
|
||||||
|
"id": "x_9y6CpZGlPJ",
|
||||||
|
"outputId": "465bc1e8-fcbc-44d5-cf5f-0ed8e61bc7b9"
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"go: creating new go.mod: module github.com/sugarme/playgo\n",
|
||||||
|
"go: downloading github.com/sugarme/gotch v0.3.2\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"$rm -f -- go.mod\n",
|
||||||
|
"$go mod init github.com/sugarme/playgo\n",
|
||||||
|
"$go get github.com/sugarme/gotch@v0.3.2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "0obqcV4KW013"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import(\n",
|
||||||
|
" \"fmt\"\n",
|
||||||
|
"\n",
|
||||||
|
" \"github.com/sugarme/gotch\"\n",
|
||||||
|
" ts \"github.com/sugarme/gotch/tensor\"\n",
|
||||||
|
") "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "9fL6QTwbT7kX"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Basic Tensor Operations"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"base_uri": "https://localhost:8080/"
|
||||||
|
},
|
||||||
|
"id": "YkLmNrswJHYY",
|
||||||
|
"outputId": "1b4c7ac8-17a3-4f66-b295-e3cd3d8ac669"
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"(1,.,.) =\n",
|
||||||
|
"1.372 1.372 1.372 \n",
|
||||||
|
"2.774 2.774 2.774 \n",
|
||||||
|
"4.150 4.150 4.150 \n",
|
||||||
|
"2.442 2.442 2.442 \n",
|
||||||
|
"\n",
|
||||||
|
"(2,.,.) =\n",
|
||||||
|
"1.935 1.935 1.935 \n",
|
||||||
|
"2.622 2.622 2.622 \n",
|
||||||
|
"2.797 2.797 2.797 \n",
|
||||||
|
"2.602 2.602 2.602 \n",
|
||||||
|
"\n",
|
||||||
|
"(3,.,.) =\n",
|
||||||
|
"2.419 2.419 2.419 \n",
|
||||||
|
"1.901 1.901 1.901 \n",
|
||||||
|
"2.795 2.795 2.795 \n",
|
||||||
|
"2.387 2.387 2.387 \n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"297 <nil>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {
|
||||||
|
"tags": []
|
||||||
|
},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"device := gotch.NewCuda().CudaIfAvailable()\n",
|
||||||
|
"ts1, err := ts.Rand([]int64{3, 4, 5}, gotch.Double, device)\n",
|
||||||
|
"if err != nil {fmt.Print(err)}\n",
|
||||||
|
"ts2, err := ts.Ones([]int64{5, 3}, gotch.Double, device)\n",
|
||||||
|
"if err != nil { fmt.Print(err)}\n",
|
||||||
|
"\n",
|
||||||
|
"mul, err := ts1.Matmul(ts2, false)\n",
|
||||||
|
"if err != nil { fmt.Print(err)}\n",
|
||||||
|
"fmt.Printf(\"%.3f\", mul)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"accelerator": "GPU",
|
||||||
|
"colab": {
|
||||||
|
"collapsed_sections": [
|
||||||
|
"fsitX3NbLbTB",
|
||||||
|
"l6aOKEMarRNH"
|
||||||
|
],
|
||||||
|
"include_colab_link": true,
|
||||||
|
"name": "gotch-basic.ipynb",
|
||||||
|
"provenance": [],
|
||||||
|
"toc_visible": true
|
||||||
|
},
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Go",
|
||||||
|
"language": "go",
|
||||||
|
"name": "gophernotes"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": "",
|
||||||
|
"file_extension": ".go",
|
||||||
|
"mimetype": "",
|
||||||
|
"name": "go",
|
||||||
|
"nbconvert_exporter": "",
|
||||||
|
"pygments_lexer": "",
|
||||||
|
"version": "go1.14.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
||||||
|
|
|
@ -14,3 +14,6 @@ Here is an example of image inference using Yolo v3 model.
|
||||||
|
|
||||||
![Bondi Beach - Yolo inference](yolo_bondi.jpg "Bondi Beach - YOLO v3")
|
![Bondi Beach - Yolo inference](yolo_bondi.jpg "Bondi Beach - YOLO v3")
|
||||||
|
|
||||||
|
|
||||||
|
<a href="https://colab.research.google.com/github/sugarme/nb/blob/master/yolo/yolo.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user