зеркало из
				https://github.com/ssciwr/AMMICO.git
				synced 2025-10-30 21:46:04 +02:00 
			
		
		
		
	[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Этот коммит содержится в:
		
							родитель
							
								
									a31e78cac1
								
							
						
					
					
						Коммит
						75ed827958
					
				| @ -17,8 +17,10 @@ TEST_IMAGE_10 = "./test/data/IMG_3756.jpg" | |||||||
| TEST_IMAGE_11 = "./test/data/IMG_3757.jpg" | TEST_IMAGE_11 = "./test/data/IMG_3757.jpg" | ||||||
| TEST_IMAGE_12 = "./test/data/pic1.png" | TEST_IMAGE_12 = "./test/data/pic1.png" | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_analyse_image(): | def test_analyse_image(): | ||||||
|     images = [TEST_IMAGE_1, |     images = [ | ||||||
|  |         TEST_IMAGE_1, | ||||||
|         TEST_IMAGE_2, |         TEST_IMAGE_2, | ||||||
|         TEST_IMAGE_3, |         TEST_IMAGE_3, | ||||||
|         TEST_IMAGE_4, |         TEST_IMAGE_4, | ||||||
| @ -51,18 +53,42 @@ def test_analyse_image(): | |||||||
|     for key in keys: |     for key in keys: | ||||||
|         assert len(mydict[key]["3_non-deterministic summary"]) == 3 |         assert len(mydict[key]["3_non-deterministic summary"]) == 3 | ||||||
| 
 | 
 | ||||||
|     assert mydict[keys[0]]["const_image_summary"] == str("a river running through a city next to tall buildings") |     assert mydict[keys[0]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[1]]["const_image_summary"] == str("a crowd of people standing on top of a tennis court") |         "a river running through a city next to tall buildings" | ||||||
|     assert mydict[keys[2]]["const_image_summary"] == str("a crowd of people standing on top of a field") |     ) | ||||||
|     assert mydict[keys[3]]["const_image_summary"] == str("a room with a desk and a chair") |     assert mydict[keys[1]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[4]]["const_image_summary"] == str("a table with plastic containers on top of it") |         "a crowd of people standing on top of a tennis court" | ||||||
|     assert mydict[keys[5]]["const_image_summary"] == str("a view of a city with mountains in the background") |     ) | ||||||
|     assert mydict[keys[6]]["const_image_summary"] == str("a view of a city street from a window") |     assert mydict[keys[2]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[7]]["const_image_summary"] == str("a busy city street with cars and pedestrians") |         "a crowd of people standing on top of a field" | ||||||
|     assert mydict[keys[8]]["const_image_summary"] == str("a close up of an open book with writing on it") |     ) | ||||||
|     assert mydict[keys[9]]["const_image_summary"] == str("a book that is open on a table") |     assert mydict[keys[3]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[10]]["const_image_summary"] == str("a yellow book with green lettering on it") |         "a room with a desk and a chair" | ||||||
|     assert mydict[keys[11]]["const_image_summary"] == str("a person running on a beach near a rock formation") |     ) | ||||||
|  |     assert mydict[keys[4]]["const_image_summary"] == str( | ||||||
|  |         "a table with plastic containers on top of it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[5]]["const_image_summary"] == str( | ||||||
|  |         "a view of a city with mountains in the background" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[6]]["const_image_summary"] == str( | ||||||
|  |         "a view of a city street from a window" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[7]]["const_image_summary"] == str( | ||||||
|  |         "a busy city street with cars and pedestrians" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[8]]["const_image_summary"] == str( | ||||||
|  |         "a close up of an open book with writing on it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[9]]["const_image_summary"] == str( | ||||||
|  |         "a book that is open on a table" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[10]]["const_image_summary"] == str( | ||||||
|  |         "a yellow book with green lettering on it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[11]]["const_image_summary"] == str( | ||||||
|  |         "a person running on a beach near a rock formation" | ||||||
|  |     ) | ||||||
| 
 | 
 | ||||||
|     for key in mydict: |     for key in mydict: | ||||||
|         mydict[key] = sm.SummaryDetector(mydict[key]).analyse_image( |         mydict[key] = sm.SummaryDetector(mydict[key]).analyse_image( | ||||||
| @ -73,18 +99,42 @@ def test_analyse_image(): | |||||||
|     for key in keys: |     for key in keys: | ||||||
|         assert len(mydict[key]["3_non-deterministic summary"]) == 3 |         assert len(mydict[key]["3_non-deterministic summary"]) == 3 | ||||||
| 
 | 
 | ||||||
|     assert mydict[keys[0]]["const_image_summary"] == str("a river running through a city next to tall buildings") |     assert mydict[keys[0]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[1]]["const_image_summary"] == str("a crowd of people standing on top of a tennis court") |         "a river running through a city next to tall buildings" | ||||||
|     assert mydict[keys[2]]["const_image_summary"] == str("a crowd of people standing on top of a field") |     ) | ||||||
|     assert mydict[keys[3]]["const_image_summary"] == str("a room with a desk and a chair") |     assert mydict[keys[1]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[4]]["const_image_summary"] == str("a table with plastic containers on top of it") |         "a crowd of people standing on top of a tennis court" | ||||||
|     assert mydict[keys[5]]["const_image_summary"] == str("a view of a city with mountains in the background") |     ) | ||||||
|     assert mydict[keys[6]]["const_image_summary"] == str("a view of a city street from a window") |     assert mydict[keys[2]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[7]]["const_image_summary"] == str("a busy city street with cars and pedestrians") |         "a crowd of people standing on top of a field" | ||||||
|     assert mydict[keys[8]]["const_image_summary"] == str("a close up of an open book with writing on it") |     ) | ||||||
|     assert mydict[keys[9]]["const_image_summary"] == str("a book that is open on a table") |     assert mydict[keys[3]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[10]]["const_image_summary"] == str("a yellow book with green lettering on it") |         "a room with a desk and a chair" | ||||||
|     assert mydict[keys[11]]["const_image_summary"] == str("a person running on a beach near a rock formation") |     ) | ||||||
|  |     assert mydict[keys[4]]["const_image_summary"] == str( | ||||||
|  |         "a table with plastic containers on top of it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[5]]["const_image_summary"] == str( | ||||||
|  |         "a view of a city with mountains in the background" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[6]]["const_image_summary"] == str( | ||||||
|  |         "a view of a city street from a window" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[7]]["const_image_summary"] == str( | ||||||
|  |         "a busy city street with cars and pedestrians" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[8]]["const_image_summary"] == str( | ||||||
|  |         "a close up of an open book with writing on it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[9]]["const_image_summary"] == str( | ||||||
|  |         "a book that is open on a table" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[10]]["const_image_summary"] == str( | ||||||
|  |         "a yellow book with green lettering on it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[11]]["const_image_summary"] == str( | ||||||
|  |         "a person running on a beach near a rock formation" | ||||||
|  |     ) | ||||||
| 
 | 
 | ||||||
|     summary_model, summary_vis_processors, _ = load_model_and_preprocess( |     summary_model, summary_vis_processors, _ = load_model_and_preprocess( | ||||||
|         name="blip_caption", |         name="blip_caption", | ||||||
| @ -102,21 +152,47 @@ def test_analyse_image(): | |||||||
|     for key in keys: |     for key in keys: | ||||||
|         assert len(mydict[key]["3_non-deterministic summary"]) == 3 |         assert len(mydict[key]["3_non-deterministic summary"]) == 3 | ||||||
| 
 | 
 | ||||||
|     assert mydict[keys[0]]["const_image_summary"] == str("a river running through a town next to tall buildings") |     assert mydict[keys[0]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[1]]["const_image_summary"] == str("a crowd of people standing on top of a track") |         "a river running through a town next to tall buildings" | ||||||
|     assert mydict[keys[2]]["const_image_summary"] == str("a group of people standing on top of a track") |     ) | ||||||
|     assert mydict[keys[3]]["const_image_summary"] == str("a desk and chair in a small room") |     assert mydict[keys[1]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[4]]["const_image_summary"] == str("a table that has some chairs on top of it") |         "a crowd of people standing on top of a track" | ||||||
|     assert mydict[keys[5]]["const_image_summary"] == str("a view of a city from a window of a building") |     ) | ||||||
|     assert mydict[keys[6]]["const_image_summary"] == str("a view of a city from a window") |     assert mydict[keys[2]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[7]]["const_image_summary"] == str("a city street filled with lots of traffic") |         "a group of people standing on top of a track" | ||||||
|     assert mydict[keys[8]]["const_image_summary"] == str("an open book with german text on it") |     ) | ||||||
|     assert mydict[keys[9]]["const_image_summary"] == str("a close up of a book on a table") |     assert mydict[keys[3]]["const_image_summary"] == str( | ||||||
|     assert mydict[keys[10]]["const_image_summary"] == str("a book with a green cover on a table") |         "a desk and chair in a small room" | ||||||
|     assert mydict[keys[11]]["const_image_summary"] == str("a person running on a beach near the ocean") |     ) | ||||||
|  |     assert mydict[keys[4]]["const_image_summary"] == str( | ||||||
|  |         "a table that has some chairs on top of it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[5]]["const_image_summary"] == str( | ||||||
|  |         "a view of a city from a window of a building" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[6]]["const_image_summary"] == str( | ||||||
|  |         "a view of a city from a window" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[7]]["const_image_summary"] == str( | ||||||
|  |         "a city street filled with lots of traffic" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[8]]["const_image_summary"] == str( | ||||||
|  |         "an open book with german text on it" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[9]]["const_image_summary"] == str( | ||||||
|  |         "a close up of a book on a table" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[10]]["const_image_summary"] == str( | ||||||
|  |         "a book with a green cover on a table" | ||||||
|  |     ) | ||||||
|  |     assert mydict[keys[11]]["const_image_summary"] == str( | ||||||
|  |         "a person running on a beach near the ocean" | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def test_analyse_questions(): | def test_analyse_questions(): | ||||||
|     images = [TEST_IMAGE_1, |     images = [ | ||||||
|  |         TEST_IMAGE_1, | ||||||
|         TEST_IMAGE_2, |         TEST_IMAGE_2, | ||||||
|         TEST_IMAGE_3, |         TEST_IMAGE_3, | ||||||
|         TEST_IMAGE_4, |         TEST_IMAGE_4, | ||||||
| @ -135,7 +211,11 @@ def test_analyse_questions(): | |||||||
|         mydict[id_] = {"filename": img_path} |         mydict[id_] = {"filename": img_path} | ||||||
| 
 | 
 | ||||||
|     summary_device = device("cuda" if cuda.is_available() else "cpu") |     summary_device = device("cuda" if cuda.is_available() else "cpu") | ||||||
|     (summary_VQA_model, summary_VQA_vis_processors, summary_VQA_txt_processors,) = load_model_and_preprocess( |     ( | ||||||
|  |         summary_VQA_model, | ||||||
|  |         summary_VQA_vis_processors, | ||||||
|  |         summary_VQA_txt_processors, | ||||||
|  |     ) = load_model_and_preprocess( | ||||||
|         name="blip_vqa", model_type="vqav2", is_eval=True, device=summary_device |         name="blip_vqa", model_type="vqav2", is_eval=True, device=summary_device | ||||||
|     ) |     ) | ||||||
|     list_of_questions = [ |     list_of_questions = [ | ||||||
| @ -143,7 +223,9 @@ def test_analyse_questions(): | |||||||
|         "What happends on the picture?", |         "What happends on the picture?", | ||||||
|     ] |     ] | ||||||
|     for key in mydict: |     for key in mydict: | ||||||
|         mydict[key] = sm.SummaryDetector(mydict[key]).analyse_questions(list_of_questions) |         mydict[key] = sm.SummaryDetector(mydict[key]).analyse_questions( | ||||||
|  |             list_of_questions | ||||||
|  |         ) | ||||||
| 
 | 
 | ||||||
|     keys = list(mydict.keys()) |     keys = list(mydict.keys()) | ||||||
|     assert len(mydict) == 12 |     assert len(mydict) == 12 | ||||||
| @ -173,4 +255,3 @@ def test_analyse_questions(): | |||||||
|     assert mydict[keys[9]][list_of_questions[1]] == str("nothing") |     assert mydict[keys[9]][list_of_questions[1]] == str("nothing") | ||||||
|     assert mydict[keys[10]][list_of_questions[1]] == str("nothing") |     assert mydict[keys[10]][list_of_questions[1]] == str("nothing") | ||||||
|     assert mydict[keys[11]][list_of_questions[1]] == str("running") |     assert mydict[keys[11]][list_of_questions[1]] == str("running") | ||||||
| 
 |  | ||||||
|  | |||||||
		Загрузка…
	
	
			
			x
			
			
		
	
		Ссылка в новой задаче
	
	Block a user
	![66853113+pre-commit-ci[bot]@users.noreply.github.com](/assets/img/avatar_default.png) pre-commit-ci[bot]
						pre-commit-ci[bot]