jupyter prediction, multiple tests

master
ml server 2020-01-15 16:07:19 -07:00
parent 8929e7182f
commit 14fc5083c6
1 changed files with 75 additions and 140 deletions

View File

@ -355,7 +355,7 @@
"source": [
"#print(test_img)\n",
"#test_img = os.path.join(test_dir, 'waterfall.png')\n",
"display(Image(os.path.join(test_dir, 'unvetted/waterfall.png')))"
"#display(Image(os.path.join(test_dir, 'unvetted/waterfall.png')))"
]
},
{
@ -529,7 +529,7 @@
"metadata": {},
"outputs": [],
"source": [
"plotImages(sample_test_images[0:1])"
"plotImages(sample_test_images[0:3])"
]
},
{
@ -551,6 +551,26 @@
"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Produces a result, quality ??? XXX\n",
"#model = Sequential([\n",
"# Conv2D(16, 3, padding='same', activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH ,3)),\n",
"# MaxPooling2D(),\n",
"# Conv2D(32, 3, padding='same', activation='relu'),\n",
"# MaxPooling2D(),\n",
"# Conv2D(64, 3, padding='same', activation='relu'),\n",
"# MaxPooling2D(),\n",
"# Flatten(),\n",
"# Dense(512, activation='relu'),\n",
"# Dense(1, activation='sigmoid')\n",
"#])"
]
},
{
"cell_type": "code",
"execution_count": null,
@ -626,52 +646,27 @@
},
{
"cell_type": "code",
"execution_count": 319,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TRAINING info\n"
]
}
],
"outputs": [],
"source": [
"print(\"TRAINING info\")"
]
},
{
"cell_type": "code",
"execution_count": 320,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"data/train\n"
]
}
],
"outputs": [],
"source": [
"print(train_dir)"
]
},
{
"cell_type": "code",
"execution_count": 321,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"data/train/good\n",
"data/train/bad\n"
]
}
],
"outputs": [],
"source": [
"print(train_good_dir)\n",
"print(train_bad_dir)"
@ -679,41 +674,25 @@
},
{
"cell_type": "code",
"execution_count": 322,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<tensorflow.python.keras.preprocessing.image.ImageDataGenerator object at 0x7f0864059e80>\n"
]
}
],
"outputs": [],
"source": [
"print(train_image_generator)"
]
},
{
"cell_type": "code",
"execution_count": 323,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<keras_preprocessing.image.directory_iterator.DirectoryIterator object at 0x7f084076d048>\n"
]
}
],
"outputs": [],
"source": [
"print(train_data_gen)"
]
},
{
"cell_type": "code",
"execution_count": 332,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -722,24 +701,16 @@
},
{
"cell_type": "code",
"execution_count": 325,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<tensorflow.python.keras.callbacks.History object at 0x7f08642b4390>\n"
]
}
],
"outputs": [],
"source": [
"print(history)"
]
},
{
"cell_type": "code",
"execution_count": 334,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -770,17 +741,9 @@
},
{
"cell_type": "code",
"execution_count": 327,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"predict\n"
]
}
],
"outputs": [],
"source": [
"# https://keras.io/models/sequential/\n",
"print(\"predict\")"
@ -788,17 +751,9 @@
},
{
"cell_type": "code",
"execution_count": 328,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4/4 [==============================] - 1s 220ms/step\n"
]
}
],
"outputs": [],
"source": [
"pred=model.predict_generator(test_data_gen,\n",
"steps=4,\n",
@ -807,18 +762,9 @@
},
{
"cell_type": "code",
"execution_count": 335,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1/1 - 0s\n",
"end predict\n"
]
}
],
"outputs": [],
"source": [
"prediction = model.predict(\n",
" x=test_data_gen,\n",
@ -836,7 +782,7 @@
},
{
"cell_type": "code",
"execution_count": 336,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -845,17 +791,9 @@
},
{
"cell_type": "code",
"execution_count": 337,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.9941876]]\n"
]
}
],
"outputs": [],
"source": [
"# Show prediction score\n",
"print(prediction)"
@ -863,17 +801,9 @@
},
{
"cell_type": "code",
"execution_count": 338,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[False]]\n"
]
}
],
"outputs": [],
"source": [
"#prediction_bool = (prediction >0.5)\n",
"prediction_bool = (prediction == 1)\n",
@ -882,17 +812,9 @@
},
{
"cell_type": "code",
"execution_count": 339,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0]]\n"
]
}
],
"outputs": [],
"source": [
"predictions = prediction_bool.astype(int)\n",
"print(predictions)"
@ -900,20 +822,12 @@
},
{
"cell_type": "code",
"execution_count": 345,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Observation: bad\n"
]
}
],
"outputs": [],
"source": [
"# Make final prediction\n",
"if prediction_bool == False:\n",
"if prediction_bool[0] == False:\n",
" rating = 'bad'\n",
"else:\n",
" rating = 'good'\n",
@ -925,14 +839,26 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"if prediction_bool[1] == False:\n",
" rating = 'bad'\n",
"else:\n",
" rating = 'good'\n",
"print('Observation: %s' % (rating))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"if prediction_bool[2] == False:\n",
" rating = 'bad'\n",
"else:\n",
" rating = 'good'\n",
"print('Observation: %s' % (rating))"
]
},
{
"cell_type": "code",
@ -1611,6 +1537,15 @@
" rating = 'good'\n",
"print('Observation: %s' % (rating))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# THE END"
]
}
],
"metadata": {