Сравнить коммиты

...

2 Коммитов

Автор SHA1 Сообщение Дата
Inga Ulusoy
a832142c44
fix: update function calls, remove obsolete stuff 2025-10-24 08:54:38 +02:00
Inga Ulusoy
1f2642f1b4
fix: update function call in notebook to conform with renaming 2025-10-24 08:35:26 +02:00
2 изменённых файлов: 30 добавлений и 45 удалений

Просмотреть файл

@ -275,7 +275,6 @@ class EmotionDetector(AnalysisMethod):
# one dictionary per face that is detected in the image
# since we are only passing a subregion of the image
# that contains one face, the list will only contain one dict
print("actions are:", self.actions)
if self.actions != []:
fresult["result"] = DeepFace.analyze(
img_path=face,

Просмотреть файл

@ -142,7 +142,7 @@
"outputs": [],
"source": [
"os.environ[\"GOOGLE_APPLICATION_CREDENTIALS\"] = (\n",
" \"/home/inga/projects/misinformation-project/misinformation-notes/misinformation-campaign-981aa55a3b13.json\"\n",
" \"../../data/misinformation-campaign-981aa55a3b13.json\"\n",
")"
]
},
@ -276,8 +276,7 @@
"# dump file name\n",
"dump_file = \"dump_file.csv\"\n",
"# dump every N images\n",
"dump_every = 10\n",
"print(len(image_dict))"
"dump_every = 10"
]
},
{
@ -358,6 +357,11 @@
"For the computationally demanding `SummaryDetector`, it is best to initialize the model first and then analyze each image while passing the model explicitly. This can be done in a separate loop or in the same loop as for text and emotion detection."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
@ -370,7 +374,7 @@
" subdict=image_dict, summary_model=model\n",
")\n",
"\n",
"image_summary_detector.analyse_images(analysis_type=\"summary\")"
"image_summary_detector.analyse_images_from_dict(analysis_type=\"summary\")"
]
},
{
@ -387,11 +391,18 @@
"outputs": [],
"source": [
"# initialize the models\n",
"# currently this does not work because of the way the summary detector is implemented\n",
"image_summary_detector = ammico.SummaryDetector(\n",
" subdict=image_dict, analysis_type=\"summary\", model_type=\"base\"\n",
")\n",
"\n",
"model = ammico.MultimodalSummaryModel()\n",
"image_summary_detector = ammico.ImageSummaryDetector(\n",
" subdict=image_dict, summary_model=model\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for num, key in tqdm(\n",
" enumerate(image_dict.keys()), total=len(image_dict)\n",
"): # loop through all images\n",
@ -399,9 +410,9 @@
" image_dict[key]\n",
" ).analyse_image() # analyse image with EmotionDetector and update dict\n",
" image_dict[key] = ammico.TextDetector(\n",
" image_dict[key], analyse_text=True\n",
" image_dict[key]\n",
" ).analyse_image() # analyse image with TextDetector and update dict\n",
" image_dict[key] = image_summary_detector.analyse_image(\n",
" image_dict[key] = image_summary_detector.analyse_images_from_dict(\n",
" subdict=image_dict[key], analysis_type=\"summary\"\n",
" ) # analyse image with SummaryDetector and update dict\n",
"\n",
@ -465,7 +476,7 @@
"metadata": {},
"outputs": [],
"source": [
"image_df.to_csv(\"/content/drive/MyDrive/misinformation-data/data_out.csv\")"
"image_df.to_csv(\"data_out.csv\")"
]
},
{
@ -484,7 +495,7 @@
"metadata": {},
"outputs": [],
"source": [
"ta = ammico.TextAnalyzer(csv_path=\"../data/ref/test.csv\", column_key=\"text\")"
"ta = ammico.TextAnalyzer(csv_path=\"test.csv\", column_key=\"text\")"
]
},
{
@ -584,7 +595,7 @@
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"GOOGLE_APPLICATION_CREDENTIALS\"] = \"/content/drive/MyDrive/misinformation-data/misinformation-campaign-981aa55a3b13.json\"\n"
"# os.environ[\"GOOGLE_APPLICATION_CREDENTIALS\"] = \"<path_to_your_service_account_key>.json\"\n"
]
},
{
@ -607,13 +618,6 @@
"): # loop through all images\n",
" image_dict[key] = ammico.TextDetector(\n",
" image_dict[key], # analyse image with TextDetector and update dict\n",
" analyse_text=True,\n",
" model_names=[\n",
" \"sshleifer/distilbart-cnn-12-6\",\n",
" \"distilbert-base-uncased-finetuned-sst-2-english\",\n",
" \"dbmdz/bert-large-cased-finetuned-conll03-english\",\n",
" ],\n",
" revision_numbers=[\"a4f8f3e\", \"af0f99b\", \"f2482bf\"],\n",
" ).analyse_image()\n",
"\n",
" if (\n",
@ -631,7 +635,7 @@
"source": [
"# write output to csv\n",
"image_df = ammico.get_dataframe(image_dict)\n",
"image_df.to_csv(\"/content/drive/MyDrive/misinformation-data/data_out.csv\")"
"image_df.to_csv(\"data_out.csv\")"
]
},
{
@ -1030,7 +1034,7 @@
"source": [
"# write output to csv\n",
"image_df = ammico.get_dataframe(image_dict)\n",
"image_df.to_csv(\"/content/drive/MyDrive/misinformation-data/data_out.csv\")"
"image_df.to_csv(\"data_out.csv\")"
]
},
{
@ -1440,24 +1444,6 @@
"The output are N primary colors and their corresponding percentage."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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, you can skip this and directly export a csv file in the step below.\n",
"Here, we display the color detection results provided by `colorgram` and `colour` libraries. Click on the tabs to see the results in the right sidebar. You may need to increment the `port` number if you are already running several notebook instances on the same server."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"analysis_explorer = ammico.AnalysisExplorer(image_dict)\n",
"analysis_explorer.run_server(port=8057)"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -1520,7 +1506,7 @@
"metadata": {},
"outputs": [],
"source": [
"df.to_csv(\"/content/drive/MyDrive/misinformation-data/data_out.csv\")"
"df.to_csv(\"data_out.csv\")"
]
},
{
@ -1528,7 +1514,7 @@
"metadata": {},
"source": [
"## Further detector modules\n",
"Further detector modules exist, also it is possible to carry out a topic analysis on the text data, as well as crop social media posts automatically. These are more experimental features and have their own demonstration notebooks."
"Please get in touch or open an issue, if you would like to propose further detector modules."
]
},
{
@ -1553,7 +1539,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.13"
"version": "3.11.14"
}
},
"nbformat": 4,