Upload CAPMIT1003.py
Browse files- CAPMIT1003.py +20 -14
CAPMIT1003.py
CHANGED
|
@@ -87,7 +87,7 @@ class CapMIT1003DB:
|
|
| 87 |
Data frame with columns `click_id`, `obs_uid`, `x`, `y`, and `click_time`. See accompanying readme for full
|
| 88 |
documentation of columns.
|
| 89 |
"""
|
| 90 |
-
return pd.read_sql_query('SELECT x, y, click_time
|
| 91 |
params=[obs_uid])
|
| 92 |
|
| 93 |
@staticmethod
|
|
@@ -116,15 +116,14 @@ class CapMIT1003(datasets.GeneratorBasedBuilder):
|
|
| 116 |
features=datasets.Features(
|
| 117 |
{
|
| 118 |
"obs_uid": datasets.Value("string"),
|
| 119 |
-
"usr_uid": datasets.Value("string"),
|
| 120 |
# "start_time": datasets.Value("timestamp"),
|
| 121 |
"caption": datasets.Value("string"),
|
| 122 |
# "img_uid": datasets.Value("string"),
|
| 123 |
# "img_path": datasets.Value("string"),
|
| 124 |
"image": datasets.Image(),
|
| 125 |
#"click_id": datasets.Value("int32"),
|
| 126 |
-
|
| 127 |
-
# "y": datasets.Value("int16"),
|
| 128 |
# "click_time": datasets.Value("timestamp")
|
| 129 |
}
|
| 130 |
),
|
|
@@ -136,36 +135,43 @@ class CapMIT1003(datasets.GeneratorBasedBuilder):
|
|
| 136 |
)
|
| 137 |
|
| 138 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 139 |
-
urls_to_download = {"
|
| 140 |
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
|
|
|
| 141 |
|
| 142 |
return [
|
| 143 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"
|
| 144 |
]
|
| 145 |
|
| 146 |
|
| 147 |
-
def _generate_examples(self,
|
| 148 |
#CapMIT1003DB.download_images()
|
| 149 |
-
logger.warning(f"filepath is: {
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
logger.warning("inside")
|
| 152 |
image_captions = db.get_captions()
|
| 153 |
logger.warning(f"captions: {image_captions}")
|
| 154 |
for pair in image_captions.itertuples(index=False):
|
| 155 |
-
logger.
|
| 156 |
caption = pair.caption
|
| 157 |
obs_uid = pair.obs_uid
|
| 158 |
click_path = db.get_click_path(obs_uid)
|
| 159 |
-
|
|
|
|
| 160 |
#click_times = click_path["click_time"].values
|
| 161 |
-
usr_uid =
|
| 162 |
example = {
|
| 163 |
"obs_uid": obs_uid,
|
| 164 |
-
"usr_uid": usr_uid,
|
| 165 |
"image": pair.img_path,
|
| 166 |
"caption": caption,
|
| 167 |
-
|
| 168 |
# "click_times": click_times
|
| 169 |
}
|
| 170 |
|
| 171 |
yield obs_uid, example
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
Data frame with columns `click_id`, `obs_uid`, `x`, `y`, and `click_time`. See accompanying readme for full
|
| 88 |
documentation of columns.
|
| 89 |
"""
|
| 90 |
+
return pd.read_sql_query('SELECT x, y, click_time AS time FROM clicks WHERE obs_uid = ?', self.cnx,
|
| 91 |
params=[obs_uid])
|
| 92 |
|
| 93 |
@staticmethod
|
|
|
|
| 116 |
features=datasets.Features(
|
| 117 |
{
|
| 118 |
"obs_uid": datasets.Value("string"),
|
| 119 |
+
# "usr_uid": datasets.Value("string"),
|
| 120 |
# "start_time": datasets.Value("timestamp"),
|
| 121 |
"caption": datasets.Value("string"),
|
| 122 |
# "img_uid": datasets.Value("string"),
|
| 123 |
# "img_path": datasets.Value("string"),
|
| 124 |
"image": datasets.Image(),
|
| 125 |
#"click_id": datasets.Value("int32"),
|
| 126 |
+
"clicks_path": datasets.Value("int16"),
|
|
|
|
| 127 |
# "click_time": datasets.Value("timestamp")
|
| 128 |
}
|
| 129 |
),
|
|
|
|
| 135 |
)
|
| 136 |
|
| 137 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 138 |
+
urls_to_download = {"mit1003": self._URLS}
|
| 139 |
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 140 |
+
downloaded_db = dl_manager.download({"cap1003": ["./capmit1003.db"]})
|
| 141 |
|
| 142 |
return [
|
| 143 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"mit1003_path": downloaded_files["mit1003"], "capmit1003_db_path": downloaded_db["cap1003"]}),
|
| 144 |
]
|
| 145 |
|
| 146 |
|
| 147 |
+
def _generate_examples(self, mit1003_path, capmit1003_db_path):
|
| 148 |
#CapMIT1003DB.download_images()
|
| 149 |
+
logger.warning(f"filepath is: {mit1003_path}")
|
| 150 |
+
logger.warning(f"db is: {capmit1003_db_path}")
|
| 151 |
+
logger.warning(f"filepath is: {mit1003_path[0]}")
|
| 152 |
+
with CapMIT1003DB(os.path.join(capmit1003_db_path[0]), os.path.join(mit1003_path[0], "ALLSTIMULI")) as db:
|
| 153 |
logger.warning("inside")
|
| 154 |
image_captions = db.get_captions()
|
| 155 |
logger.warning(f"captions: {image_captions}")
|
| 156 |
for pair in image_captions.itertuples(index=False):
|
| 157 |
+
logger.info(f"{pair.caption}")
|
| 158 |
caption = pair.caption
|
| 159 |
obs_uid = pair.obs_uid
|
| 160 |
click_path = db.get_click_path(obs_uid)
|
| 161 |
+
xy_coordinates = click_path[['x', 'y']].values
|
| 162 |
+
logger.info(xy_coordinates)
|
| 163 |
#click_times = click_path["click_time"].values
|
| 164 |
+
# usr_uid = pair["usr_uid"].values
|
| 165 |
example = {
|
| 166 |
"obs_uid": obs_uid,
|
| 167 |
+
# "usr_uid": usr_uid,
|
| 168 |
"image": pair.img_path,
|
| 169 |
"caption": caption,
|
| 170 |
+
"clicks_path": xy_coordinates,
|
| 171 |
# "click_times": click_times
|
| 172 |
}
|
| 173 |
|
| 174 |
yield obs_uid, example
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
#datasets-cli test CapMIT1003/CAPMIT1003.py --save_info --all_configs
|