create a rotation diff
"\n",
" dataset = dataset.repeat().batch(batch_size)\n",
" \n",
- " return dataset\n",
- "\n",
- "test_dataset = create_pipeline_dataset(1)"
+ " return dataset"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "batch_two_dataset = create_pipeline_dataset(2)\n",
- "\n",
- "for parameters, img in batch_two_dataset.take(3): \n",
+ "for parameters, img in create_pipeline_dataset(2).take(3): \n",
" dim = img.shape\n",
" print(dim)\n",
" for i in range(dim[0]): \n",
" return new_parameters\n",
"\n",
"\n",
- "for parameters, img in test_dataset.take(1):\n",
+ "for parameters, img in create_pipeline_dataset(1).take(1):\n",
" flipped_parameters = flip_parameters(parameters)\n",
" \n",
" print(parameters)\n",
" axs[0,0].set_title(\"Flipped\")"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def determine_rotation_diff(predicted_parameters, ground_truth_parameters):\n",
+ " predicted_rotations = predicted_parameters[:, 4] * 180\n",
+ " ground_truth_rotations = ground_truth_parameters[:, 4] * 180\n",
+ " \n",
+ " diff_rotation = (predicted_rotations - ground_truth_rotations) % 180\n",
+ " diff_rotation = tf.reduce_min(tf.stack([diff_rotation, 180 - diff_rotation]), axis=0)\n",
+ " \n",
+ " return diff_rotation\n",
+ "\n",
+ "\n",
+ "def adjust_rotation(parameters, degrees):\n",
+ " new_parameters = tf.concat([\n",
+ " parameters[:,0:4],\n",
+ " parameters[:,4:5] + degrees/180,\n",
+ " parameters[:,5::]\n",
+ " ], axis=-1)\n",
+ " \n",
+ " return new_parameters\n",
+ "\n",
+ "\n",
+ "for parameters, img in create_pipeline_dataset(4).take(1): \n",
+ " print(determine_rotation_diff(parameters, parameters))\n",
+ " print(determine_rotation_diff(parameters, adjust_rotation(parameters, 1)))\n",
+ " print(determine_rotation_diff(parameters, adjust_rotation(parameters, 89)))\n",
+ " print(determine_rotation_diff(parameters, adjust_rotation(parameters, 180)))\n",
+ " print(determine_rotation_diff(parameters, adjust_rotation(parameters, 181)))\n",
+ " print(determine_rotation_diff(parameters, adjust_rotation(parameters, 179)))"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
"source": [
"BATCH_SIZE = 10\n",
"\n",
+ "test_dataset = create_pipeline_dataset(1)\n",
"train_dataset = create_pipeline_dataset(BATCH_SIZE)\n",
"optimizer = tf.keras.optimizers.Adam(learning_rate=0.1, beta_1=0.5)\n",
"\n",
