summaryrefslogtreecommitdiff
path: root/opus_calibration/eval.ipynb
blob: 1cc477648ebd0ea04e0fe6c2174edb58e30dc561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.genfromtxt('results.txt', delimiter=\" \")\n",
    "x.sort(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# some smoothing\n",
    "ex = np.exp(x[:, 1])\n",
    "ex_smooth = ex.copy()\n",
    "ex_smooth[1:-1] = (ex[1:-1] + ex[0:-2] + ex[2:]) / 3\n",
    "ex_smooth[0] = (ex[0] + ex[1]) / 2\n",
    "ex_smooth[-1] = (ex[-1] + ex[-2]) / 2\n",
    "y_smooth = np.log(ex_smooth)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# restrict bitrate range\n",
    "bitrates = list(x[:, 0])\n",
    "mos = list(x[:, 1])\n",
    "stop_idx = bitrates.index(22000) + 1\n",
    "\n",
    "bitrates = bitrates[:stop_idx]\n",
    "mos = mos[:stop_idx]\n",
    "\n",
    "\n",
    "num_bitrates = 100\n",
    "a, b = mos[0], mos[-1]\n",
    "points = a + (b - a) * np.arange(num_bitrates) / (num_bitrates - 1)\n",
    "\n",
    "sample_bitrates = np.interp(points, mos, bitrates)\n",
    "\n",
    "print(f\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6000,  6059,  6119,  6178,  6237,  6296,  6356,  6415,  6474,\n",
       "        6520,  6556,  6592,  6628,  6664,  6700,  6736,  6772,  6808,\n",
       "        6844,  6880,  6916,  6952,  6988,  7028,  7071,  7114,  7157,\n",
       "        7199,  7242,  7285,  7327,  7370,  7413,  7455,  7498,  7527,\n",
       "        7556,  7584,  7613,  7642,  7670,  7699,  7728,  7756,  7785,\n",
       "        7813,  7842,  7871,  7899,  7928,  7956,  7985,  8039,  8121,\n",
       "        8202,  8284,  8366,  8447,  8533,  8625,  8718,  8810,  8903,\n",
       "        8995,  9119,  9244,  9369,  9495,  9569,  9640,  9712,  9783,\n",
       "        9855,  9926,  9998, 10162, 10329, 10495, 10691, 10888, 11108,\n",
       "       11359, 11562, 11704, 11846, 11988, 12299, 12678, 13126, 13519,\n",
       "       13750, 13980, 14521, 15223, 15708, 16108, 17163, 17817, 19010,\n",
       "       20000], dtype=int32)"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_bitrates.round().astype(np.int32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(sample_bitrates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}