Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- BloodCell/bloodcell_unique_questions.json +0 -0
- BloodCell/bloodcell_unique_questions_original.json +0 -0
- BloodCell/extract_unique_questions.py +173 -0
- all_question_images/BloodCell__7_2449.jpeg +3 -0
- all_question_images/BloodCell__7_4331.jpeg +3 -0
- all_question_images/BloodCell__7_469.jpeg +3 -0
- all_question_images/BloodCell__7_4735.jpeg +3 -0
- all_question_images/BloodCell__7_5121.jpeg +3 -0
- all_question_images/BloodCell__7_5344.jpeg +3 -0
- all_question_images/BloodCell__7_5436.jpeg +3 -0
- all_question_images/BloodCell__7_5453.jpeg +3 -0
- all_question_images/BloodCell__7_5506.jpeg +3 -0
- all_question_images/BloodCell__7_5553.jpeg +3 -0
- all_question_images/BloodCell__7_5975.jpeg +3 -0
- all_question_images/BloodCell__7_6084.jpeg +3 -0
- all_question_images/BloodCell__7_658.jpeg +3 -0
- all_question_images/BloodCell__7_6748.jpeg +3 -0
- all_question_images/BloodCell__7_7059.jpeg +3 -0
- all_question_images/BloodCell__7_7193.jpeg +3 -0
- all_question_images/BloodCell__7_7576.jpeg +3 -0
- all_question_images/BloodCell__7_7792.jpeg +3 -0
- all_question_images/BloodCell__7_7792_1.jpeg +3 -0
- all_question_images/BloodCell__7_7916.jpeg +3 -0
- all_question_images/BloodCell__81_881.jpeg +3 -0
- all_question_images/BloodCell__82_4825.jpeg +3 -0
- all_question_images/BloodCell__83_1754.jpeg +3 -0
- all_question_images/BloodCell__83_6500.jpeg +3 -0
- all_question_images/BloodCell__84_1699.jpeg +3 -0
- all_question_images/BloodCell__84_3744.jpeg +3 -0
- all_question_images/BloodCell__84_7013.jpeg +3 -0
- all_question_images/BloodCell__85_6143.jpeg +3 -0
- all_question_images/BloodCell__86_1106.jpeg +3 -0
- all_question_images/BloodCell__87_9772.jpeg +3 -0
- all_question_images/BloodCell__88_3626.jpeg +3 -0
- all_question_images/BloodCell__88_8453.jpeg +3 -0
- all_question_images/BloodCell__8_2087.jpeg +3 -0
- all_question_images/BloodCell__8_2087_1.jpeg +3 -0
- all_question_images/BloodCell__8_2196.jpeg +3 -0
- all_question_images/BloodCell__8_2560.jpeg +3 -0
- all_question_images/BloodCell__8_3373.jpeg +3 -0
- all_question_images/BloodCell__8_3731.jpeg +3 -0
- all_question_images/BloodCell__8_3771.jpeg +3 -0
- all_question_images/BloodCell__8_4167.jpeg +3 -0
- all_question_images/BloodCell__8_4361.jpeg +3 -0
- all_question_images/BloodCell__8_471.jpeg +3 -0
- all_question_images/BloodCell__8_4999.jpeg +3 -0
- all_question_images/BloodCell__8_5577.jpeg +3 -0
- all_question_images/BloodCell__8_6098.jpeg +3 -0
- all_question_images/BloodCell__8_6363.jpeg +3 -0
- all_question_images/BloodCell__8_6424.jpeg +3 -0
BloodCell/bloodcell_unique_questions.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
BloodCell/bloodcell_unique_questions_original.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
BloodCell/extract_unique_questions.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from typing import List, Dict
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def get_random_image_path(answer: str) -> str:
|
| 9 |
+
"""
|
| 10 |
+
Get a random image path based on the answer type.
|
| 11 |
+
|
| 12 |
+
Args:
|
| 13 |
+
answer (str): The answer to determine which folder to select from
|
| 14 |
+
|
| 15 |
+
Returns:
|
| 16 |
+
str: Random image path from the appropriate folder
|
| 17 |
+
"""
|
| 18 |
+
base_path = "BloodCell/BloodCell/TRAIN"
|
| 19 |
+
|
| 20 |
+
# Map answer names to directory names
|
| 21 |
+
answer_to_dir = {
|
| 22 |
+
"eosinophils": "EOSINOPHIL",
|
| 23 |
+
"lymphocytes": "LYMPHOCYTE",
|
| 24 |
+
"monocytes": "MONOCYTE",
|
| 25 |
+
"neutrophils": "NEUTROPHIL"
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
if answer == "Microscopy":
|
| 29 |
+
# Select randomly from all images in TRAIN directory
|
| 30 |
+
image_files = []
|
| 31 |
+
for root, _, files in os.walk(base_path):
|
| 32 |
+
for file in files:
|
| 33 |
+
if file.endswith('.jpeg'):
|
| 34 |
+
image_files.append(os.path.join(root, file))
|
| 35 |
+
elif answer in answer_to_dir:
|
| 36 |
+
# Select randomly from the specific cell type directory
|
| 37 |
+
cell_type_path = os.path.join(base_path, answer_to_dir[answer])
|
| 38 |
+
if not os.path.exists(cell_type_path):
|
| 39 |
+
raise ValueError(f"Directory not found for cell type: {answer}")
|
| 40 |
+
|
| 41 |
+
image_files = []
|
| 42 |
+
for file in os.listdir(cell_type_path):
|
| 43 |
+
if file.endswith('.jpeg'):
|
| 44 |
+
image_files.append(os.path.join(cell_type_path, file))
|
| 45 |
+
else:
|
| 46 |
+
raise ValueError(f"Unknown answer type: {answer}")
|
| 47 |
+
|
| 48 |
+
if not image_files:
|
| 49 |
+
raise ValueError(f"No images found for answer type: {answer}")
|
| 50 |
+
|
| 51 |
+
# Select a random image
|
| 52 |
+
random_image = random.choice(image_files)
|
| 53 |
+
return random_image
|
| 54 |
+
|
| 55 |
+
def extract_unique_questions(json_data: List[Dict]) -> Dict[str, Dict]:
|
| 56 |
+
"""
|
| 57 |
+
Extract unique questions from the JSON data where questions with different answers are considered different.
|
| 58 |
+
Saves the complete original question item for each unique question.
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
json_data (List[Dict]): List of dictionaries containing question data
|
| 62 |
+
|
| 63 |
+
Returns:
|
| 64 |
+
Dict[str, Dict]: Dictionary mapping unique questions to their complete original items
|
| 65 |
+
"""
|
| 66 |
+
unique_questions = {}
|
| 67 |
+
|
| 68 |
+
for item in json_data:
|
| 69 |
+
question = item['question']
|
| 70 |
+
answer = item['gt_answer']
|
| 71 |
+
|
| 72 |
+
# Create a key that combines question and answer to ensure uniqueness
|
| 73 |
+
key = f"{question}|{answer}"
|
| 74 |
+
|
| 75 |
+
if key not in unique_questions:
|
| 76 |
+
# Create a copy of the item to avoid modifying the original
|
| 77 |
+
new_item = item.copy()
|
| 78 |
+
# Replace the image path with a random one based on the answer
|
| 79 |
+
new_item['image_path'] = get_random_image_path(answer)
|
| 80 |
+
unique_questions[key] = new_item
|
| 81 |
+
|
| 82 |
+
return unique_questions
|
| 83 |
+
|
| 84 |
+
def extend_to_100_questions(unique_questions: Dict[str, Dict]) -> List[Dict]:
|
| 85 |
+
"""
|
| 86 |
+
Extend the number of questions to 100 by randomly duplicating existing questions.
|
| 87 |
+
|
| 88 |
+
Args:
|
| 89 |
+
unique_questions (Dict[str, Dict]): Dictionary of unique questions
|
| 90 |
+
|
| 91 |
+
Returns:
|
| 92 |
+
List[Dict]: List of 100 questions
|
| 93 |
+
"""
|
| 94 |
+
questions_list = list(unique_questions.values())
|
| 95 |
+
current_count = len(questions_list)
|
| 96 |
+
|
| 97 |
+
# If we already have more than 100 questions, just return the first 100
|
| 98 |
+
if current_count >= 800:
|
| 99 |
+
return questions_list#[:100]
|
| 100 |
+
|
| 101 |
+
# Calculate how many more questions we need
|
| 102 |
+
needed = 800 - current_count
|
| 103 |
+
|
| 104 |
+
# Randomly select questions to duplicate
|
| 105 |
+
for _ in range(needed):
|
| 106 |
+
# Select a random question
|
| 107 |
+
random_question = random.choice(questions_list)
|
| 108 |
+
# Create a copy of the question
|
| 109 |
+
new_question = random_question.copy()
|
| 110 |
+
# Generate a new random image path based on the answer
|
| 111 |
+
new_question['image_path'] = get_random_image_path(new_question['gt_answer'])
|
| 112 |
+
# Add to the list
|
| 113 |
+
questions_list.append(new_question)
|
| 114 |
+
|
| 115 |
+
return questions_list
|
| 116 |
+
|
| 117 |
+
def refill_question_ids(questions: List[Dict]) -> List[Dict]:
|
| 118 |
+
"""
|
| 119 |
+
Refill question_ids with sequential IDs.
|
| 120 |
+
|
| 121 |
+
Args:
|
| 122 |
+
questions (List[Dict]): List of questions
|
| 123 |
+
|
| 124 |
+
Returns:
|
| 125 |
+
List[Dict]: List of questions with sequential IDs
|
| 126 |
+
"""
|
| 127 |
+
for i, question in enumerate(questions):
|
| 128 |
+
# Format the ID with leading zeros to maintain 4 digits
|
| 129 |
+
question['question_id'] = f"BloodCell_{i:04d}"
|
| 130 |
+
return questions
|
| 131 |
+
|
| 132 |
+
def main():
|
| 133 |
+
# Set random seed for reproducibility
|
| 134 |
+
random.seed(42)
|
| 135 |
+
|
| 136 |
+
# First convert all BMP images to JPG
|
| 137 |
+
# convert_bmp_to_jpg()
|
| 138 |
+
|
| 139 |
+
# Read the JSON file
|
| 140 |
+
with open('../Original_open/Blood Cell.json', 'r') as f:
|
| 141 |
+
data = json.load(f)
|
| 142 |
+
|
| 143 |
+
# Print all unique answers
|
| 144 |
+
unique_answers = set(item['gt_answer'] for item in data)
|
| 145 |
+
print("\nUnique answers in the original file:")
|
| 146 |
+
for answer in sorted(unique_answers):
|
| 147 |
+
print(f"- {answer}")
|
| 148 |
+
print(f"\nTotal number of unique answers: {len(unique_answers)}")
|
| 149 |
+
|
| 150 |
+
# Extract unique questions
|
| 151 |
+
unique_questions = extract_unique_questions(data)
|
| 152 |
+
|
| 153 |
+
# Save the unique questions first
|
| 154 |
+
unique_questions_list = list(unique_questions.values())
|
| 155 |
+
with open('BloodCell/bloodcell_unique_questions_original.json', 'w') as f:
|
| 156 |
+
json.dump(unique_questions_list, f, indent=4)
|
| 157 |
+
print(f"\nOriginal unique questions have been saved to 'BloodCell/bloodcell_unique_questions_original.json'")
|
| 158 |
+
print(f"Number of unique questions: {len(unique_questions_list)}")
|
| 159 |
+
|
| 160 |
+
# # Extend to 100 questions
|
| 161 |
+
extended_questions = extend_to_100_questions(unique_questions)
|
| 162 |
+
|
| 163 |
+
# Refill question IDs sequentially
|
| 164 |
+
final_questions = refill_question_ids(extended_questions)
|
| 165 |
+
|
| 166 |
+
# Save the extended questions to a new JSON file
|
| 167 |
+
with open('BloodCell/bloodcell_unique_questions.json', 'w') as f:
|
| 168 |
+
json.dump(final_questions, f, indent=4)
|
| 169 |
+
print(f"\nExtended questions have been saved to 'BloodCell/bloodcell_unique_questions.json'")
|
| 170 |
+
print(f"Extended to {len(final_questions)} questions")
|
| 171 |
+
|
| 172 |
+
if __name__ == "__main__":
|
| 173 |
+
main()
|
all_question_images/BloodCell__7_2449.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_4331.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_469.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_4735.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_5121.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_5344.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_5436.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_5453.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_5506.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_5553.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_5975.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_6084.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_658.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_6748.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_7059.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_7193.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_7576.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_7792.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_7792_1.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__7_7916.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__81_881.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__82_4825.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__83_1754.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__83_6500.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__84_1699.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__84_3744.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__84_7013.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__85_6143.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__86_1106.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__87_9772.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__88_3626.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__88_8453.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_2087.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_2087_1.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_2196.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_2560.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_3373.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_3731.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_3771.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_4167.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_4361.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_471.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_4999.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_5577.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_6098.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_6363.jpeg
ADDED
|
Git LFS Details
|
all_question_images/BloodCell__8_6424.jpeg
ADDED
|
Git LFS Details
|