Skip to content

Commit 1a49903

Browse files
author
jangsoopark
committed
Noise simulation
1 parent 6ef89d8 commit 1a49903

File tree

2 files changed

+16
-37
lines changed

2 files changed

+16
-37
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ $ python3 train.py
159159

160160
- Noise Simulation [1]
161161
- i.i.d samples from a uniform distribution
162+
- This simulation does not fix the random seed
162163

163164
| Noise | 1% | 5% | 10% | 15%|
164165
| :---: | :---: | :---: | :---: | :---: |

notebook/experiments-SOC.ipynb

+15-37
Original file line numberDiff line numberDiff line change
@@ -288,45 +288,22 @@
288288
},
289289
{
290290
"cell_type": "code",
291-
"execution_count": 15,
292-
"metadata": {},
293-
"outputs": [],
294-
"source": [
295-
"from skimage import util"
296-
]
297-
},
298-
{
299-
"cell_type": "code",
300-
"execution_count": 77,
301-
"metadata": {},
302-
"outputs": [
303-
{
304-
"data": {
305-
"text/plain": [
306-
"(614.0, 7744)"
307-
]
308-
},
309-
"execution_count": 77,
310-
"metadata": {},
311-
"output_type": "execute_result"
312-
}
313-
],
314-
"source": [
315-
"util.random_noise(np.zeros((88, 88)), mode='s&p', amount=0.15).sum(), 88 * 88"
316-
]
317-
},
318-
{
319-
"cell_type": "code",
320-
"execution_count": 99,
291+
"execution_count": 105,
321292
"metadata": {},
322293
"outputs": [],
323294
"source": [
295+
"from skimage import util\n",
296+
"\n",
297+
"\n",
324298
"def generate_noise(_images, amount):\n",
325299
" \n",
326300
" n, _, h, w = _images.shape\n",
327301
" \n",
328-
" noise = np.random.uniform(size=(n, 1, h, w))\n",
329-
" portions = util.random_noise(np.zeros((n, 1, 88, 88)), mode='s&p', amount=amount)\n",
302+
" noise = np.array([np.random.uniform(size=(1, h, w)) for _ in range(n)])\n",
303+
" portions = np.array([\n",
304+
" util.random_noise(np.zeros((1, 88, 88)), mode='s&p', amount=amount)\n",
305+
" for _ in range(n)\n",
306+
" ])\n",
330307
" noise = noise * portions\n",
331308
" \n",
332309
" return _images + noise.astype(np.float32)\n",
@@ -352,22 +329,23 @@
352329
" corrects += (predictions == labels.to(m.device)).sum().item()\n",
353330
"\n",
354331
" accuracy = 100 * corrects / num_data\n",
332+
" \n",
355333
" return accuracy"
356334
]
357335
},
358336
{
359337
"cell_type": "code",
360-
"execution_count": 103,
338+
"execution_count": 106,
361339
"metadata": {},
362340
"outputs": [
363341
{
364342
"name": "stdout",
365343
"output_type": "stream",
366344
"text": [
367-
"ratio = 0.01, accuracy = 98.56\n",
368-
"ratio = 0.05, accuracy = 94.39\n",
369-
"ratio = 0.10, accuracy = 85.03\n",
370-
"ratio = 0.15, accuracy = 73.65\n"
345+
"ratio = 0.01, accuracy = 98.23\n",
346+
"ratio = 0.05, accuracy = 94.19\n",
347+
"ratio = 0.10, accuracy = 85.28\n",
348+
"ratio = 0.15, accuracy = 73.40\n"
371349
]
372350
}
373351
],

0 commit comments

Comments
 (0)