fix usage of gather_nd
"# print(minimisation_stack)\n",
" \n",
" min_index = tf.argmin(minimisation_stack, axis=0)\n",
+ " a_range = tf.range(min_index.shape[0], dtype=tf.int64)\n",
+ " min_index = tf.stack([\n",
+ " min_index, a_range\n",
+ " ], axis=-1)\n",
+ " \n",
+ " \n",
" \n",
"# print(min_index)\n",
" \n",
+ "# print(non_flipped_diff)\n",
+ "# print(flipped_diff)\n",
+ " \n",
" both_diffs = tf.stack([\n",
" non_flipped_diff, flipped_diff\n",
" ])\n",
- "# print(both_diffs.numpy()[min_index, :, :])\n",
+ " print(both_diffs)\n",
+ " print(min_index)\n",
"\n",
- " diff = tf.gather(\n",
- " both_diffs, min_index, axis=0\n",
+ " diff = tf.gather_nd(\n",
+ " both_diffs, min_index\n",
" )\n",
" \n",
- "# diff = tf.convert_to_tensor(both_diffs.numpy()[min_index, :, :])\n",
" return diff\n",
"\n",
"\n",
- "for parameters, img in create_pipeline_dataset(4).take(1):\n",
+ "for parameters, img in create_pipeline_dataset(2).take(1):\n",
" flipped_parameters = flip_parameters(parameters)\n",
- " print(determine_corrected_diff(parameters, parameters))\n",
- " print(determine_corrected_diff(parameters, flipped_parameters))\n",
- " print(determine_corrected_diff(flipped_parameters, parameters))"
+ " print(determine_corrected_diff(parameters, parameters + 0.5))\n",
+ "# print(determine_corrected_diff(parameters, flipped_parameters))\n",
+ "# print(determine_corrected_diff(flipped_parameters, parameters))"
]
},
{
"source": [
"def loss_function(predicted_parameters, ground_truth_parameters):\n",
" diff = determine_corrected_diff(predicted_parameters, ground_truth_parameters)\n",
- " loss = diff ** 2\n",
+ " loss = tf.abs(diff)\n",
"\n",
" return loss\n",
"\n",
"\n",
- "for parameters, img in create_pipeline_dataset(2).take(1):\n",
- " print(parameters)\n",
- " print(loss_function(parameters, parameters))\n",
- " print(loss_function(parameters, parameters + 1))\n",
+ "# for parameters, img in create_pipeline_dataset(1).take(1):\n",
+ "# print(parameters)\n",
+ "# print(loss_function(parameters, parameters))\n",
+ "# print(loss_function(parameters, parameters + 1))\n",
+ " \n",
+ " \n",
+ "for parameters, img in create_pipeline_dataset(3).take(1):\n",
" print(loss_function(parameters, parameters + 0.5))"
]
},
