-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_numpy.py
50 lines (43 loc) · 1.55 KB
/
train_numpy.py
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
import numpy as np
import utils_numpy
import aicrowd_helpers
from numba import cuda
def hack(x):
"""
A dummy numpy function.
Parameters
----------
x : numpy.ndarray
Input images. Expect these to have the shape (N, C, H, W), where N is the
number of batches (processed in parallel), C is the number of channels (= 3),
and (H, W) the dimensions of the image (height and width).
Returns
-------
numpy.ndarray
The representation, which must be (N, C').
"""
reprs = []
# Append a few pixels here and there
reprs.append(x[:, :, 32, 32].mean(-1))
reprs.append(x[:, :, 16, 32].mean(-1))
reprs.append(x[:, :, 32, 16].mean(-1))
reprs.append(x[:, :, -16, 32].mean(-1))
reprs.append(x[:, :, 32, -16].mean(-1))
# Append some global statistics
reprs.append(x.mean((1, 2, 3)))
reprs.append(x.var((1, 2, 3)))
# Make representation and return
reprs = np.stack(reprs, axis=-1)
return reprs
if __name__ == '__main__':
########################################################################
# Register Execution Start
########################################################################
aicrowd_helpers.execution_start()
utils_numpy.export_function(hack)
aicrowd_helpers.register_progress(1.0)
########################################################################
# Submit Results for evaluation
########################################################################
cuda.close()
aicrowd_helpers.submit()