Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- VITON-Extends-Train/data/__pycache__/__init__.cpython-36.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/__init__.cpython-37.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/base_data_loader.cpython-36.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/custom_dataset_data_loader.cpython-36.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/custom_dataset_data_loader_test.cpython-36.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/data_loader.cpython-36.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/data_loader_test.cpython-36.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/image_folder.cpython-36.pyc +0 -0
- VITON-Extends-Train/data/__pycache__/image_folder.cpython-37.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/__init__.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/__init__.cpython-37.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/afwm.cpython-37.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/base_model.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_add.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_add.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_add.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_feat.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_grid_offset_sep.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_grid_sep.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_new.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_offset.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more_heatmap.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more_no_refine.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more_trans.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_sep.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_cor_sep.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_smooth.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/flow_gmm_vis.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/models.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/networks.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/networks.cpython-37.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/networks_flow.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/pix2pixHD_model.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/__pycache__/predict_mask.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/correlation/README.md +1 -0
- VITON-Extends-Train/models/correlation/__pycache__/correlation.cpython-36.pyc +0 -0
- VITON-Extends-Train/models/correlation/__pycache__/correlation.cpython-37.pyc +0 -0
- VITON-Extends-Train/models/correlation/correlation.py +405 -0
- VITON-Extends-Train/options/__pycache__/__init__.cpython-36.pyc +0 -0
- VITON-Extends-Train/options/__pycache__/__init__.cpython-37.pyc +0 -0
- VITON-Extends-Train/options/__pycache__/base_options.cpython-36.pyc +0 -0
- VITON-Extends-Train/options/__pycache__/base_options.cpython-37.pyc +0 -0
VITON-Extends-Train/data/__pycache__/__init__.cpython-36.pyc
ADDED
|
Binary file (151 Bytes). View file
|
|
|
VITON-Extends-Train/data/__pycache__/__init__.cpython-37.pyc
ADDED
|
Binary file (137 Bytes). View file
|
|
|
VITON-Extends-Train/data/__pycache__/base_data_loader.cpython-36.pyc
ADDED
|
Binary file (692 Bytes). View file
|
|
|
VITON-Extends-Train/data/__pycache__/custom_dataset_data_loader.cpython-36.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
VITON-Extends-Train/data/__pycache__/custom_dataset_data_loader_test.cpython-36.pyc
ADDED
|
Binary file (1.48 kB). View file
|
|
|
VITON-Extends-Train/data/__pycache__/data_loader.cpython-36.pyc
ADDED
|
Binary file (416 Bytes). View file
|
|
|
VITON-Extends-Train/data/__pycache__/data_loader_test.cpython-36.pyc
ADDED
|
Binary file (426 Bytes). View file
|
|
|
VITON-Extends-Train/data/__pycache__/image_folder.cpython-36.pyc
ADDED
|
Binary file (2.72 kB). View file
|
|
|
VITON-Extends-Train/data/__pycache__/image_folder.cpython-37.pyc
ADDED
|
Binary file (2.7 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/__init__.cpython-36.pyc
ADDED
|
Binary file (153 Bytes). View file
|
|
|
VITON-Extends-Train/models/__pycache__/__init__.cpython-37.pyc
ADDED
|
Binary file (139 Bytes). View file
|
|
|
VITON-Extends-Train/models/__pycache__/afwm.cpython-37.pyc
ADDED
|
Binary file (8.93 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/base_model.cpython-36.pyc
ADDED
|
Binary file (2.64 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm.cpython-36.pyc
ADDED
|
Binary file (8.41 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_add.cpython-36.pyc
ADDED
|
Binary file (8.4 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor.cpython-36.pyc
ADDED
|
Binary file (9.37 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_add.cpython-36.pyc
ADDED
|
Binary file (9.08 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more.cpython-36.pyc
ADDED
|
Binary file (10.2 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_add.cpython-36.pyc
ADDED
|
Binary file (9.36 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_feat.cpython-36.pyc
ADDED
|
Binary file (9.77 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_grid_offset_sep.cpython-36.pyc
ADDED
|
Binary file (10.3 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_grid_sep.cpython-36.pyc
ADDED
|
Binary file (10.3 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_new.cpython-36.pyc
ADDED
|
Binary file (10.2 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_offset.cpython-36.pyc
ADDED
|
Binary file (10.1 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise.cpython-36.pyc
ADDED
|
Binary file (10.1 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new.cpython-36.pyc
ADDED
|
Binary file (10.1 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep.cpython-36.pyc
ADDED
|
Binary file (10.2 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all.cpython-36.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more.cpython-36.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more_heatmap.cpython-36.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more_no_refine.cpython-36.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_revise_new_sep_all_more_trans.cpython-36.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_more_sep.cpython-36.pyc
ADDED
|
Binary file (9.97 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_cor_sep.cpython-36.pyc
ADDED
|
Binary file (9.48 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_smooth.cpython-36.pyc
ADDED
|
Binary file (9.08 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/flow_gmm_vis.cpython-36.pyc
ADDED
|
Binary file (10.5 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/models.cpython-36.pyc
ADDED
|
Binary file (706 Bytes). View file
|
|
|
VITON-Extends-Train/models/__pycache__/networks.cpython-36.pyc
ADDED
|
Binary file (51.6 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/networks.cpython-37.pyc
ADDED
|
Binary file (6.41 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/networks_flow.cpython-36.pyc
ADDED
|
Binary file (22.6 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/pix2pixHD_model.cpython-36.pyc
ADDED
|
Binary file (13 kB). View file
|
|
|
VITON-Extends-Train/models/__pycache__/predict_mask.cpython-36.pyc
ADDED
|
Binary file (1.54 kB). View file
|
|
|
VITON-Extends-Train/models/correlation/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
This is an adaptation of the <a href="https://github.com/lmb-freiburg/flownet2">FlowNet2 implementation</a> in order to compute cost volumes. Should you be making use of this work, please make sure to adhere to the <a href="https://github.com/lmb-freiburg/flownet2#license-and-citation">licensing terms</a> of the original authors. Should you be making use or modify this particular implementation, please acknowledge it appropriately.
|
VITON-Extends-Train/models/correlation/__pycache__/correlation.cpython-36.pyc
ADDED
|
Binary file (13.6 kB). View file
|
|
|
VITON-Extends-Train/models/correlation/__pycache__/correlation.cpython-37.pyc
ADDED
|
Binary file (13.6 kB). View file
|
|
|
VITON-Extends-Train/models/correlation/correlation.py
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
| 12 |
+
const float* input,
|
| 13 |
+
float* output
|
| 14 |
+
) {
|
| 15 |
+
int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x;
|
| 16 |
+
|
| 17 |
+
if (intIndex >= n) {
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
int intSample = blockIdx.z;
|
| 22 |
+
int intChannel = blockIdx.y;
|
| 23 |
+
|
| 24 |
+
float fltValue = input[(((intSample * SIZE_1(input)) + intChannel) * SIZE_2(input) * SIZE_3(input)) + intIndex];
|
| 25 |
+
|
| 26 |
+
__syncthreads();
|
| 27 |
+
|
| 28 |
+
int intPaddedY = (intIndex / SIZE_3(input)) + 3*{{intStride}};
|
| 29 |
+
int intPaddedX = (intIndex % SIZE_3(input)) + 3*{{intStride}};
|
| 30 |
+
int intRearrange = ((SIZE_3(input) + 6*{{intStride}}) * intPaddedY) + intPaddedX;
|
| 31 |
+
|
| 32 |
+
output[(((intSample * SIZE_1(output) * SIZE_2(output)) + intRearrange) * SIZE_1(input)) + intChannel] = fltValue;
|
| 33 |
+
}
|
| 34 |
+
'''
|
| 35 |
+
|
| 36 |
+
kernel_Correlation_updateOutput = '''
|
| 37 |
+
extern "C" __global__ void kernel_Correlation_updateOutput(
|
| 38 |
+
const int n,
|
| 39 |
+
const float* rbot0,
|
| 40 |
+
const float* rbot1,
|
| 41 |
+
float* top
|
| 42 |
+
) {
|
| 43 |
+
extern __shared__ char patch_data_char[];
|
| 44 |
+
|
| 45 |
+
float *patch_data = (float *)patch_data_char;
|
| 46 |
+
|
| 47 |
+
// First (upper left) position of kernel upper-left corner in current center position of neighborhood in image 1
|
| 48 |
+
int x1 = (blockIdx.x + 3) * {{intStride}};
|
| 49 |
+
int y1 = (blockIdx.y + 3) * {{intStride}};
|
| 50 |
+
int item = blockIdx.z;
|
| 51 |
+
int ch_off = threadIdx.x;
|
| 52 |
+
|
| 53 |
+
// Load 3D patch into shared shared memory
|
| 54 |
+
for (int j = 0; j < 1; j++) { // HEIGHT
|
| 55 |
+
for (int i = 0; i < 1; i++) { // WIDTH
|
| 56 |
+
int ji_off = (j + i) * SIZE_3(rbot0);
|
| 57 |
+
for (int ch = ch_off; ch < SIZE_3(rbot0); ch += 32) { // CHANNELS
|
| 58 |
+
int idx1 = ((item * SIZE_1(rbot0) + y1+j) * SIZE_2(rbot0) + x1+i) * SIZE_3(rbot0) + ch;
|
| 59 |
+
int idxPatchData = ji_off + ch;
|
| 60 |
+
patch_data[idxPatchData] = rbot0[idx1];
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
__syncthreads();
|
| 66 |
+
|
| 67 |
+
__shared__ float sum[32];
|
| 68 |
+
|
| 69 |
+
// Compute correlation
|
| 70 |
+
for (int top_channel = 0; top_channel < SIZE_1(top); top_channel++) {
|
| 71 |
+
sum[ch_off] = 0;
|
| 72 |
+
|
| 73 |
+
int s2o = (top_channel % 7 - 3) * {{intStride}};
|
| 74 |
+
int s2p = (top_channel / 7 - 3) * {{intStride}};
|
| 75 |
+
|
| 76 |
+
for (int j = 0; j < 1; j++) { // HEIGHT
|
| 77 |
+
for (int i = 0; i < 1; i++) { // WIDTH
|
| 78 |
+
int ji_off = (j + i) * SIZE_3(rbot0);
|
| 79 |
+
for (int ch = ch_off; ch < SIZE_3(rbot0); ch += 32) { // CHANNELS
|
| 80 |
+
int x2 = x1 + s2o;
|
| 81 |
+
int y2 = y1 + s2p;
|
| 82 |
+
|
| 83 |
+
int idxPatchData = ji_off + ch;
|
| 84 |
+
int idx2 = ((item * SIZE_1(rbot0) + y2+j) * SIZE_2(rbot0) + x2+i) * SIZE_3(rbot0) + ch;
|
| 85 |
+
|
| 86 |
+
sum[ch_off] += patch_data[idxPatchData] * rbot1[idx2];
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
__syncthreads();
|
| 92 |
+
|
| 93 |
+
if (ch_off == 0) {
|
| 94 |
+
float total_sum = 0;
|
| 95 |
+
for (int idx = 0; idx < 32; idx++) {
|
| 96 |
+
total_sum += sum[idx];
|
| 97 |
+
}
|
| 98 |
+
const int sumelems = SIZE_3(rbot0);
|
| 99 |
+
const int index = ((top_channel*SIZE_2(top) + blockIdx.y)*SIZE_3(top))+blockIdx.x;
|
| 100 |
+
top[index + item*SIZE_1(top)*SIZE_2(top)*SIZE_3(top)] = total_sum / (float)sumelems;
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
'''
|
| 105 |
+
|
| 106 |
+
kernel_Correlation_updateGradFirst = '''
|
| 107 |
+
#define ROUND_OFF 50000
|
| 108 |
+
|
| 109 |
+
extern "C" __global__ void kernel_Correlation_updateGradFirst(
|
| 110 |
+
const int n,
|
| 111 |
+
const int intSample,
|
| 112 |
+
const float* rbot0,
|
| 113 |
+
const float* rbot1,
|
| 114 |
+
const float* gradOutput,
|
| 115 |
+
float* gradFirst,
|
| 116 |
+
float* gradSecond
|
| 117 |
+
) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) {
|
| 118 |
+
int n = intIndex % SIZE_1(gradFirst); // channels
|
| 119 |
+
int l = (intIndex / SIZE_1(gradFirst)) % SIZE_3(gradFirst) + 3*{{intStride}}; // w-pos
|
| 120 |
+
int m = (intIndex / SIZE_1(gradFirst) / SIZE_3(gradFirst)) % SIZE_2(gradFirst) + 3*{{intStride}}; // h-pos
|
| 121 |
+
|
| 122 |
+
// round_off is a trick to enable integer division with ceil, even for negative numbers
|
| 123 |
+
// We use a large offset, for the inner part not to become negative.
|
| 124 |
+
const int round_off = ROUND_OFF;
|
| 125 |
+
const int round_off_s1 = {{intStride}} * round_off;
|
| 126 |
+
|
| 127 |
+
// We add round_off before_s1 the int division and subtract round_off after it, to ensure the formula matches ceil behavior:
|
| 128 |
+
int xmin = (l - 3*{{intStride}} + round_off_s1 - 1) / {{intStride}} + 1 - round_off; // ceil (l - 3*{{intStride}}) / {{intStride}}
|
| 129 |
+
int ymin = (m - 3*{{intStride}} + round_off_s1 - 1) / {{intStride}} + 1 - round_off; // ceil (l - 3*{{intStride}}) / {{intStride}}
|
| 130 |
+
|
| 131 |
+
// Same here:
|
| 132 |
+
int xmax = (l - 3*{{intStride}} + round_off_s1) / {{intStride}} - round_off; // floor (l - 3*{{intStride}}) / {{intStride}}
|
| 133 |
+
int ymax = (m - 3*{{intStride}} + round_off_s1) / {{intStride}} - round_off; // floor (m - 3*{{intStride}}) / {{intStride}}
|
| 134 |
+
|
| 135 |
+
float sum = 0;
|
| 136 |
+
if (xmax>=0 && ymax>=0 && (xmin<=SIZE_3(gradOutput)-1) && (ymin<=SIZE_2(gradOutput)-1)) {
|
| 137 |
+
xmin = max(0,xmin);
|
| 138 |
+
xmax = min(SIZE_3(gradOutput)-1,xmax);
|
| 139 |
+
|
| 140 |
+
ymin = max(0,ymin);
|
| 141 |
+
ymax = min(SIZE_2(gradOutput)-1,ymax);
|
| 142 |
+
|
| 143 |
+
for (int p = -3; p <= 3; p++) {
|
| 144 |
+
for (int o = -3; o <= 3; o++) {
|
| 145 |
+
// Get rbot1 data:
|
| 146 |
+
int s2o = {{intStride}} * o;
|
| 147 |
+
int s2p = {{intStride}} * p;
|
| 148 |
+
int idxbot1 = ((intSample * SIZE_1(rbot0) + (m+s2p)) * SIZE_2(rbot0) + (l+s2o)) * SIZE_3(rbot0) + n;
|
| 149 |
+
float bot1tmp = rbot1[idxbot1]; // rbot1[l+s2o,m+s2p,n]
|
| 150 |
+
|
| 151 |
+
// Index offset for gradOutput in following loops:
|
| 152 |
+
int op = (p+3) * 7 + (o+3); // index[o,p]
|
| 153 |
+
int idxopoffset = (intSample * SIZE_1(gradOutput) + op);
|
| 154 |
+
|
| 155 |
+
for (int y = ymin; y <= ymax; y++) {
|
| 156 |
+
for (int x = xmin; x <= xmax; x++) {
|
| 157 |
+
int idxgradOutput = (idxopoffset * SIZE_2(gradOutput) + y) * SIZE_3(gradOutput) + x; // gradOutput[x,y,o,p]
|
| 158 |
+
sum += gradOutput[idxgradOutput] * bot1tmp;
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
const int sumelems = SIZE_1(gradFirst);
|
| 165 |
+
const int bot0index = ((n * SIZE_2(gradFirst)) + (m-3*{{intStride}})) * SIZE_3(gradFirst) + (l-3*{{intStride}});
|
| 166 |
+
gradFirst[bot0index + intSample*SIZE_1(gradFirst)*SIZE_2(gradFirst)*SIZE_3(gradFirst)] = sum / (float)sumelems;
|
| 167 |
+
} }
|
| 168 |
+
'''
|
| 169 |
+
|
| 170 |
+
kernel_Correlation_updateGradSecond = '''
|
| 171 |
+
#define ROUND_OFF 50000
|
| 172 |
+
|
| 173 |
+
extern "C" __global__ void kernel_Correlation_updateGradSecond(
|
| 174 |
+
const int n,
|
| 175 |
+
const int intSample,
|
| 176 |
+
const float* rbot0,
|
| 177 |
+
const float* rbot1,
|
| 178 |
+
const float* gradOutput,
|
| 179 |
+
float* gradFirst,
|
| 180 |
+
float* gradSecond
|
| 181 |
+
) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) {
|
| 182 |
+
int n = intIndex % SIZE_1(gradSecond); // channels
|
| 183 |
+
int l = (intIndex / SIZE_1(gradSecond)) % SIZE_3(gradSecond) + 3*{{intStride}}; // w-pos
|
| 184 |
+
int m = (intIndex / SIZE_1(gradSecond) / SIZE_3(gradSecond)) % SIZE_2(gradSecond) + 3*{{intStride}}; // h-pos
|
| 185 |
+
|
| 186 |
+
// round_off is a trick to enable integer division with ceil, even for negative numbers
|
| 187 |
+
// We use a large offset, for the inner part not to become negative.
|
| 188 |
+
const int round_off = ROUND_OFF;
|
| 189 |
+
const int round_off_s1 = {{intStride}} * round_off;
|
| 190 |
+
|
| 191 |
+
float sum = 0;
|
| 192 |
+
for (int p = -3; p <= 3; p++) {
|
| 193 |
+
for (int o = -3; o <= 3; o++) {
|
| 194 |
+
int s2o = {{intStride}} * o;
|
| 195 |
+
int s2p = {{intStride}} * p;
|
| 196 |
+
|
| 197 |
+
//Get X,Y ranges and clamp
|
| 198 |
+
// We add round_off before_s1 the int division and subtract round_off after it, to ensure the formula matches ceil behavior:
|
| 199 |
+
int xmin = (l - 3*{{intStride}} - s2o + round_off_s1 - 1) / {{intStride}} + 1 - round_off; // ceil (l - 3*{{intStride}} - s2o) / {{intStride}}
|
| 200 |
+
int ymin = (m - 3*{{intStride}} - s2p + round_off_s1 - 1) / {{intStride}} + 1 - round_off; // ceil (l - 3*{{intStride}} - s2o) / {{intStride}}
|
| 201 |
+
|
| 202 |
+
// Same here:
|
| 203 |
+
int xmax = (l - 3*{{intStride}} - s2o + round_off_s1) / {{intStride}} - round_off; // floor (l - 3*{{intStride}} - s2o) / {{intStride}}
|
| 204 |
+
int ymax = (m - 3*{{intStride}} - s2p + round_off_s1) / {{intStride}} - round_off; // floor (m - 3*{{intStride}} - s2p) / {{intStride}}
|
| 205 |
+
|
| 206 |
+
if (xmax>=0 && ymax>=0 && (xmin<=SIZE_3(gradOutput)-1) && (ymin<=SIZE_2(gradOutput)-1)) {
|
| 207 |
+
xmin = max(0,xmin);
|
| 208 |
+
xmax = min(SIZE_3(gradOutput)-1,xmax);
|
| 209 |
+
|
| 210 |
+
ymin = max(0,ymin);
|
| 211 |
+
ymax = min(SIZE_2(gradOutput)-1,ymax);
|
| 212 |
+
|
| 213 |
+
// Get rbot0 data:
|
| 214 |
+
int idxbot0 = ((intSample * SIZE_1(rbot0) + (m-s2p)) * SIZE_2(rbot0) + (l-s2o)) * SIZE_3(rbot0) + n;
|
| 215 |
+
float bot0tmp = rbot0[idxbot0]; // rbot1[l+s2o,m+s2p,n]
|
| 216 |
+
|
| 217 |
+
// Index offset for gradOutput in following loops:
|
| 218 |
+
int op = (p+3) * 7 + (o+3); // index[o,p]
|
| 219 |
+
int idxopoffset = (intSample * SIZE_1(gradOutput) + op);
|
| 220 |
+
|
| 221 |
+
for (int y = ymin; y <= ymax; y++) {
|
| 222 |
+
for (int x = xmin; x <= xmax; x++) {
|
| 223 |
+
int idxgradOutput = (idxopoffset * SIZE_2(gradOutput) + y) * SIZE_3(gradOutput) + x; // gradOutput[x,y,o,p]
|
| 224 |
+
sum += gradOutput[idxgradOutput] * bot0tmp;
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
const int sumelems = SIZE_1(gradSecond);
|
| 231 |
+
const int bot1index = ((n * SIZE_2(gradSecond)) + (m-3*{{intStride}})) * SIZE_3(gradSecond) + (l-3*{{intStride}});
|
| 232 |
+
gradSecond[bot1index + intSample*SIZE_1(gradSecond)*SIZE_2(gradSecond)*SIZE_3(gradSecond)] = sum / (float)sumelems;
|
| 233 |
+
} }
|
| 234 |
+
'''
|
| 235 |
+
|
| 236 |
+
def cupy_kernel(strFunction, objVariables):
|
| 237 |
+
strKernel = globals()[strFunction].replace('{{intStride}}', str(objVariables['intStride']))
|
| 238 |
+
|
| 239 |
+
while True:
|
| 240 |
+
objMatch = re.search('(SIZE_)([0-4])(\()([^\)]*)(\))', strKernel)
|
| 241 |
+
|
| 242 |
+
if objMatch is None:
|
| 243 |
+
break
|
| 244 |
+
# end
|
| 245 |
+
|
| 246 |
+
intArg = int(objMatch.group(2))
|
| 247 |
+
|
| 248 |
+
strTensor = objMatch.group(4)
|
| 249 |
+
intSizes = objVariables[strTensor].size()
|
| 250 |
+
|
| 251 |
+
strKernel = strKernel.replace(objMatch.group(), str(intSizes[intArg]))
|
| 252 |
+
# end
|
| 253 |
+
|
| 254 |
+
while True:
|
| 255 |
+
objMatch = re.search('(VALUE_)([0-4])(\()([^\)]+)(\))', strKernel)
|
| 256 |
+
|
| 257 |
+
if objMatch is None:
|
| 258 |
+
break
|
| 259 |
+
# end
|
| 260 |
+
|
| 261 |
+
intArgs = int(objMatch.group(2))
|
| 262 |
+
strArgs = objMatch.group(4).split(',')
|
| 263 |
+
|
| 264 |
+
strTensor = strArgs[0]
|
| 265 |
+
intStrides = objVariables[strTensor].stride()
|
| 266 |
+
strIndex = [ '((' + strArgs[intArg + 1].replace('{', '(').replace('}', ')').strip() + ')*' + str(intStrides[intArg]) + ')' for intArg in range(intArgs) ]
|
| 267 |
+
|
| 268 |
+
strKernel = strKernel.replace(objMatch.group(0), strTensor + '[' + str.join('+', strIndex) + ']')
|
| 269 |
+
# end
|
| 270 |
+
|
| 271 |
+
return strKernel
|
| 272 |
+
# end
|
| 273 |
+
|
| 274 |
+
@cupy.util.memoize(for_each_device=True)
|
| 275 |
+
def cupy_launch(strFunction, strKernel):
|
| 276 |
+
return cupy.cuda.compile_with_cache(strKernel).get_function(strFunction)
|
| 277 |
+
# end
|
| 278 |
+
|
| 279 |
+
class _FunctionCorrelation(torch.autograd.Function):
|
| 280 |
+
@staticmethod
|
| 281 |
+
def forward(self, first, second, intStride):
|
| 282 |
+
rbot0 = first.new_zeros([ first.shape[0], first.shape[2] + (6 * intStride), first.shape[3] + (6 * intStride), first.shape[1] ])
|
| 283 |
+
rbot1 = first.new_zeros([ first.shape[0], first.shape[2] + (6 * intStride), first.shape[3] + (6 * intStride), first.shape[1] ])
|
| 284 |
+
|
| 285 |
+
self.save_for_backward(first, second, rbot0, rbot1)
|
| 286 |
+
|
| 287 |
+
self.intStride = intStride
|
| 288 |
+
|
| 289 |
+
assert(first.is_contiguous() == True)
|
| 290 |
+
assert(second.is_contiguous() == True)
|
| 291 |
+
|
| 292 |
+
output = first.new_zeros([ first.shape[0], 49, int(math.ceil(first.shape[2] / intStride)), int(math.ceil(first.shape[3] / intStride)) ])
|
| 293 |
+
|
| 294 |
+
if first.is_cuda == True:
|
| 295 |
+
n = first.shape[2] * first.shape[3]
|
| 296 |
+
cupy_launch('kernel_Correlation_rearrange', cupy_kernel('kernel_Correlation_rearrange', {
|
| 297 |
+
'intStride': self.intStride,
|
| 298 |
+
'input': first,
|
| 299 |
+
'output': rbot0
|
| 300 |
+
}))(
|
| 301 |
+
grid=tuple([ int((n + 16 - 1) / 16), first.shape[1], first.shape[0] ]),
|
| 302 |
+
block=tuple([ 16, 1, 1 ]),
|
| 303 |
+
args=[ n, first.data_ptr(), rbot0.data_ptr() ]
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
n = second.shape[2] * second.shape[3]
|
| 307 |
+
cupy_launch('kernel_Correlation_rearrange', cupy_kernel('kernel_Correlation_rearrange', {
|
| 308 |
+
'intStride': self.intStride,
|
| 309 |
+
'input': second,
|
| 310 |
+
'output': rbot1
|
| 311 |
+
}))(
|
| 312 |
+
grid=tuple([ int((n + 16 - 1) / 16), second.shape[1], second.shape[0] ]),
|
| 313 |
+
block=tuple([ 16, 1, 1 ]),
|
| 314 |
+
args=[ n, second.data_ptr(), rbot1.data_ptr() ]
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
n = output.shape[1] * output.shape[2] * output.shape[3]
|
| 318 |
+
cupy_launch('kernel_Correlation_updateOutput', cupy_kernel('kernel_Correlation_updateOutput', {
|
| 319 |
+
'intStride': self.intStride,
|
| 320 |
+
'rbot0': rbot0,
|
| 321 |
+
'rbot1': rbot1,
|
| 322 |
+
'top': output
|
| 323 |
+
}))(
|
| 324 |
+
grid=tuple([ output.shape[3], output.shape[2], output.shape[0] ]),
|
| 325 |
+
block=tuple([ 32, 1, 1 ]),
|
| 326 |
+
shared_mem=first.shape[1] * 4,
|
| 327 |
+
args=[ n, rbot0.data_ptr(), rbot1.data_ptr(), output.data_ptr() ]
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
elif first.is_cuda == False:
|
| 331 |
+
raise NotImplementedError()
|
| 332 |
+
|
| 333 |
+
# end
|
| 334 |
+
|
| 335 |
+
return output
|
| 336 |
+
# end
|
| 337 |
+
|
| 338 |
+
@staticmethod
|
| 339 |
+
def backward(self, gradOutput):
|
| 340 |
+
first, second, rbot0, rbot1 = self.saved_tensors
|
| 341 |
+
|
| 342 |
+
assert(gradOutput.is_contiguous() == True)
|
| 343 |
+
|
| 344 |
+
gradFirst = first.new_zeros([ first.shape[0], first.shape[1], first.shape[2], first.shape[3] ]) if self.needs_input_grad[0] == True else None
|
| 345 |
+
gradSecond = first.new_zeros([ first.shape[0], first.shape[1], first.shape[2], first.shape[3] ]) if self.needs_input_grad[1] == True else None
|
| 346 |
+
|
| 347 |
+
if first.is_cuda == True:
|
| 348 |
+
if gradFirst is not None:
|
| 349 |
+
for intSample in range(first.shape[0]):
|
| 350 |
+
n = first.shape[1] * first.shape[2] * first.shape[3]
|
| 351 |
+
cupy_launch('kernel_Correlation_updateGradFirst', cupy_kernel('kernel_Correlation_updateGradFirst', {
|
| 352 |
+
'intStride': self.intStride,
|
| 353 |
+
'rbot0': rbot0,
|
| 354 |
+
'rbot1': rbot1,
|
| 355 |
+
'gradOutput': gradOutput,
|
| 356 |
+
'gradFirst': gradFirst,
|
| 357 |
+
'gradSecond': None
|
| 358 |
+
}))(
|
| 359 |
+
grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]),
|
| 360 |
+
block=tuple([ 512, 1, 1 ]),
|
| 361 |
+
args=[ n, intSample, rbot0.data_ptr(), rbot1.data_ptr(), gradOutput.data_ptr(), gradFirst.data_ptr(), None ]
|
| 362 |
+
)
|
| 363 |
+
# end
|
| 364 |
+
# end
|
| 365 |
+
|
| 366 |
+
if gradSecond is not None:
|
| 367 |
+
for intSample in range(first.shape[0]):
|
| 368 |
+
n = first.shape[1] * first.shape[2] * first.shape[3]
|
| 369 |
+
cupy_launch('kernel_Correlation_updateGradSecond', cupy_kernel('kernel_Correlation_updateGradSecond', {
|
| 370 |
+
'intStride': self.intStride,
|
| 371 |
+
'rbot0': rbot0,
|
| 372 |
+
'rbot1': rbot1,
|
| 373 |
+
'gradOutput': gradOutput,
|
| 374 |
+
'gradFirst': None,
|
| 375 |
+
'gradSecond': gradSecond
|
| 376 |
+
}))(
|
| 377 |
+
grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]),
|
| 378 |
+
block=tuple([ 512, 1, 1 ]),
|
| 379 |
+
args=[ n, intSample, rbot0.data_ptr(), rbot1.data_ptr(), gradOutput.data_ptr(), None, gradSecond.data_ptr() ]
|
| 380 |
+
)
|
| 381 |
+
# end
|
| 382 |
+
# end
|
| 383 |
+
|
| 384 |
+
elif first.is_cuda == False:
|
| 385 |
+
raise NotImplementedError()
|
| 386 |
+
|
| 387 |
+
# end
|
| 388 |
+
|
| 389 |
+
return gradFirst, gradSecond, None
|
| 390 |
+
# end
|
| 391 |
+
# end
|
| 392 |
+
|
| 393 |
+
def FunctionCorrelation(tenFirst, tenSecond, intStride):
|
| 394 |
+
return _FunctionCorrelation.apply(tenFirst, tenSecond, intStride)
|
| 395 |
+
# end
|
| 396 |
+
|
| 397 |
+
class ModuleCorrelation(torch.nn.Module):
|
| 398 |
+
def __init__(self):
|
| 399 |
+
super(ModuleCorrelation, self).__init__()
|
| 400 |
+
# end
|
| 401 |
+
|
| 402 |
+
def forward(self, tenFirst, tenSecond, intStride):
|
| 403 |
+
return _FunctionCorrelation.apply(tenFirst, tenSecond, intStride)
|
| 404 |
+
# end
|
| 405 |
+
# end
|
VITON-Extends-Train/options/__pycache__/__init__.cpython-36.pyc
ADDED
|
Binary file (154 Bytes). View file
|
|
|
VITON-Extends-Train/options/__pycache__/__init__.cpython-37.pyc
ADDED
|
Binary file (140 Bytes). View file
|
|
|
VITON-Extends-Train/options/__pycache__/base_options.cpython-36.pyc
ADDED
|
Binary file (4.53 kB). View file
|
|
|
VITON-Extends-Train/options/__pycache__/base_options.cpython-37.pyc
ADDED
|
Binary file (4.39 kB). View file
|
|
|