AMMICO/build/html/notebooks/Example objects.ipynb

1092 строки
28 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Objects Expression recognition"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebooks shows some preliminary work on detecting objects expressions with cvlib. It is mainly meant to explore its capabilities and to decide on future research directions. We package our code into a `ammico` package that is imported here:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:46:43.072679Z",
"iopub.status.busy": "2023-05-16T11:46:43.072202Z",
"iopub.status.idle": "2023-05-16T11:46:58.136488Z",
"shell.execute_reply": "2023-05-16T11:46:58.135748Z"
},
"tags": []
},
"outputs": [],
"source": [
"import ammico\n",
"from ammico import utils as mutils\n",
"from ammico import display as mdisplay\n",
"import ammico.objects as ob"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set an image path as input file path."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:46:58.140475Z",
"iopub.status.busy": "2023-05-16T11:46:58.139659Z",
"iopub.status.idle": "2023-05-16T11:46:58.143901Z",
"shell.execute_reply": "2023-05-16T11:46:58.143209Z"
},
"tags": []
},
"outputs": [],
"source": [
"images = mutils.find_files(\n",
" path=\"data/\",\n",
" limit=10,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:46:58.146946Z",
"iopub.status.busy": "2023-05-16T11:46:58.146507Z",
"iopub.status.idle": "2023-05-16T11:46:58.149810Z",
"shell.execute_reply": "2023-05-16T11:46:58.149134Z"
},
"tags": []
},
"outputs": [],
"source": [
"mydict = mutils.initialize_dict(images)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Manually inspect what was detected\n",
"\n",
"To check the analysis, you can inspect the analyzed elements here. Loading the results takes a moment, so please be patient. If you are sure of what you are doing."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:46:58.153871Z",
"iopub.status.busy": "2023-05-16T11:46:58.153428Z",
"iopub.status.idle": "2023-05-16T11:46:59.301016Z",
"shell.execute_reply": "2023-05-16T11:46:59.300195Z"
},
"tags": []
},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'ammico.display' has no attribute 'explore_analysis'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmdisplay\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexplore_analysis\u001b[49m(mydict, identify\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mobjects\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'ammico.display' has no attribute 'explore_analysis'"
]
}
],
"source": [
"mdisplay.explore_analysis(mydict, identify=\"objects\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Detect objects and directly write to csv"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:46:59.305468Z",
"iopub.status.busy": "2023-05-16T11:46:59.304965Z",
"iopub.status.idle": "2023-05-16T11:47:07.038626Z",
"shell.execute_reply": "2023-05-16T11:47:07.037611Z"
},
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0% | |\r"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading yolov4.cfg from https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4.cfg\n",
"Downloading yolov4.weights from https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0% | |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 1% | |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 2% |# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 3% |## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 4% |## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 5% |### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 6% |#### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 7% |##### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 8% |##### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 9% |###### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 10% |####### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 11% |####### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 12% |######## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 13% |######### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 14% |########## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 15% |########## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 16% |########### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 17% |############ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 18% |############ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 19% |############# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 20% |############## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 21% |############### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 22% |############### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 23% |################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 24% |################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 25% |################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 26% |################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 27% |################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 28% |#################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 29% |#################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 30% |##################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 31% |###################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 32% |####################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 33% |####################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 34% |######################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 35% |######################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 36% |######################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 37% |########################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 38% |########################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 39% |############################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 40% |############################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 41% |############################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 42% |############################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 43% |############################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 44% |############################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 45% |################################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 46% |################################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 47% |################################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 48% |################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 49% |################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 50% |#################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 51% |#################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 52% |##################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 53% |###################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 54% |###################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 55% |####################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 56% |######################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 57% |######################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 58% |######################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 59% |########################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 60% |########################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 61% |########################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 62% |############################################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 63% |############################################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 64% |############################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 65% |############################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 66% |############################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 67% |################################################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 68% |################################################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 69% |################################################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 70% |################################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 71% |################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 72% |################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 73% |#################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 74% |##################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 75% |###################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 76% |###################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 77% |####################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 78% |######################################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 79% |######################################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 80% |######################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 81% |########################################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 82% |########################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 83% |########################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 84% |############################################################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 85% |############################################################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 86% |############################################################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 87% |############################################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 88% |############################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 89% |################################################################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 90% |################################################################ |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 91% |################################################################# |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 92% |################################################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 93% |################################################################## |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 94% |################################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 95% |#################################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 96% |##################################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 97% |##################################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 98% |###################################################################### |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 99% |####################################################################### |\r"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading yolov3_classes.txt from https://github.com/arunponnusamy/object-detection-opencv/raw/master/yolov3.txt\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100% | |\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100% | |\r"
]
}
],
"source": [
"for key in mydict:\n",
" mydict[key] = ob.ObjectDetector(mydict[key]).analyse_image()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert the dictionary of dictionarys into a dictionary with lists:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:47:07.042525Z",
"iopub.status.busy": "2023-05-16T11:47:07.042007Z",
"iopub.status.idle": "2023-05-16T11:47:07.046366Z",
"shell.execute_reply": "2023-05-16T11:47:07.045638Z"
},
"tags": []
},
"outputs": [],
"source": [
"outdict = mutils.append_data_to_dict(mydict)\n",
"df = mutils.dump_df(outdict)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check the dataframe:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:47:07.049479Z",
"iopub.status.busy": "2023-05-16T11:47:07.048872Z",
"iopub.status.idle": "2023-05-16T11:47:07.063174Z",
"shell.execute_reply": "2023-05-16T11:47:07.062639Z"
},
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>filename</th>\n",
" <th>person</th>\n",
" <th>bicycle</th>\n",
" <th>car</th>\n",
" <th>motorcycle</th>\n",
" <th>airplane</th>\n",
" <th>bus</th>\n",
" <th>train</th>\n",
" <th>truck</th>\n",
" <th>boat</th>\n",
" <th>traffic light</th>\n",
" <th>cell phone</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>data/102730_eng.png</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>data/102141_2_eng.png</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>data/106349S_por.png</td>\n",
" <td>yes</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>no</td>\n",
" <td>yes</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" filename person bicycle car motorcycle airplane bus train \n",
"0 data/102730_eng.png yes no no no no no no \\\n",
"1 data/102141_2_eng.png yes no no no no no no \n",
"2 data/106349S_por.png yes no no no no no no \n",
"\n",
" truck boat traffic light cell phone \n",
"0 yes no no no \n",
"1 no no no no \n",
"2 no no no yes "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write the csv file:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-16T11:47:07.065960Z",
"iopub.status.busy": "2023-05-16T11:47:07.065505Z",
"iopub.status.idle": "2023-05-16T11:47:07.070226Z",
"shell.execute_reply": "2023-05-16T11:47:07.069685Z"
},
"tags": []
},
"outputs": [],
"source": [
"df.to_csv(\"./data_out.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"vscode": {
"interpreter": {
"hash": "f1142466f556ab37fe2d38e2897a16796906208adb09fea90ba58bdf8a56f0ba"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}