# -*- coding: utf-8 -*- """aphantasia_drawing_dataset.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1FHMQJWfjSzSrtEpARqh7IKVrfF7LwyRA """ #!pip install datasets -q #from google.colab import drive #drive.mount('/content/drive') #path = os.getcwd() + "/drive/MyDrive/Duke/huggingface_project/aphantasia_drawing" # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # TODO: Address all TODOs and remove all explanatory comments """TODO: Add a description here.""" #import csv import base64 from PIL import Image import numpy as np import io import json import os from typing import List import datasets import logging # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @misc{Bainbridge_Pounder_Eardley_Baker_2023, title={Quantifying Aphantasia through drawing: Those without visual imagery show deficits in object but not spatial memory}, url={osf.io/cahyd}, publisher={OSF}, author={Bainbridge, Wilma A and Pounder, Zoƫ and Eardley, Alison and Baker, Chris I}, year={2023}, month={Sep} } """ # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ This dataset comes from the Brain Bridge Lab from the University of Chicago. It is from an online memory drawing experiment with 61 individuals with aphantasia and 52 individuals with normal imagery. In the experiment participants 1) studied 3 separate scene photographs presented one after the other, 2) then drew them from memory, 3) completed a recognition task, 4) copied the images while viewing them, 5) filled out a VVIQ and OSIQ questionnaire and also demographics questions. The data from the experiment was made available on the OSF website linked above. It was created July 31, 2020 and last updated September 27, 2023. """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "https://osf.io/cahyd/" # TODO: Add the licence for the dataset here if you can find it _LICENSE = "" # TODO: Add link to the official dataset URLs here # The HuggingFace Datasets library doesn't host the datasets but only points to the original files. # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method) url = "https://drive.google.com/file/d/1aRhQlKPDk29yYPkx2kPhqaMwec5QZ4JE/view?usp=sharing" def _get_drive_url(url): base_url = 'https://drive.google.com/uc?id=' split_url = url.split('/') return base_url + split_url[5] _URL = {"train": _get_drive_url(url)} # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case class AphantasiaDrawingDataset(datasets.GeneratorBasedBuilder): """TODO: Short description of my dataset.""" _URL = _URL VERSION = datasets.Version("1.1.0") def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features({ "subject_id": datasets.Value("int32"), "treatment": datasets.Value("string"),#datasets.ClassLabel(names=["aphantasia", "control"]), "demographics": { "country": datasets.Value("string"), "age": datasets.Value("int32"), "gender": datasets.Value("string"), "occupation": datasets.Value("string"), "art_ability": datasets.Value("int32"), "art_experience": datasets.Value("string"), "device": datasets.Value("string"), "input": datasets.Value("string"), "difficult": datasets.Value("string"), "diff_explanation": datasets.Value("string"), "vviq_score": datasets.Value("int32"), "osiq_score": datasets.Value("int32") }, "drawings": { "kitchen": { "perception": datasets.Image(decode=True), "memory": datasets.Image(decode=True) }, "livingroom": { "perception": datasets.Image(decode=True), "memory": datasets.Image(decode=True) }, "bedroom": { "perception": datasets.Image(decode=True), "memory": datasets.Image(decode=True) } }, "image": { "kitchen": datasets.Image(decode=True), "livingroom": datasets.Image(decode=True), "bedroom": datasets.Image(decode = True) } }), # No default supervised_keys (as we have to pass both question # and context as input). supervised_keys=None, homepage=_HOMEPAGE, citation=_CITATION, ) def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: url_to_download = self._URL downloaded_file = dl_manager.download_and_extract(url_to_download) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={ "filepath": downloaded_file["train"] }) ] def _generate_examples(self, filepath): """This function returns the examples in the raw (text) form.""" logging.info("generating examples from = %s", filepath) with open(filepath, "r") as subjects_file: subjects_data = json.load(subjects_file) idx = 0 for sub in subjects_data: for room in subjects_data[sub]["drawings"].keys(): if subjects_data[sub]["drawings"][room]["perception"] != "": img_byt = base64.b64decode(subjects_data[sub]["drawings"][room]["perception"]) img = Image.open(io.BytesIO(img_byt)) subjects_data[sub]["drawings"][room]["perception"] = img else: subjects_data[sub]["drawings"][room]["perception"] = np.nan if subjects_data[sub]["drawings"][room]["memory"] != "": img_byt = base64.b64decode(subjects_data[sub]["drawings"][room]["memory"]) img = Image.open(io.BytesIO(img_byt)) subjects_data[sub]["drawings"][room]["memory"] = img else: subjects_data[sub]["drawings"][room]["memory"] = np.nan for room in subjects_data[sub]["image"].keys(): img_byt = base64.b64decode(subjects_data[sub]["image"][room]) img = Image.open(io.BytesIO(img_byt)) subjects_data[sub]["image"][room] = img.resize((500,500)) idx += 1 age = int(subjects_data[sub]["demographics"]["age"]) if subjects_data[sub]["demographics"]["age"] else np.nan yield idx-1, { "subject_id": subjects_data[sub]["subject_id"], "treatment": subjects_data[sub]["treatment"], "demographics": { "country": subjects_data[sub]["demographics"]["country"], "age": subjects_data[sub]["demographics"]["age"], "gender": subjects_data[sub]["demographics"]["gender"], "occupation": subjects_data[sub]["demographics"]["occupation"], "art_ability": subjects_data[sub]["demographics"]["art_ability"], "art_experience": subjects_data[sub]["demographics"]["art_experience"], "device": subjects_data[sub]["demographics"]["device"], "input": subjects_data[sub]["demographics"]["input"], "difficult": subjects_data[sub]["demographics"]["difficult"], "diff_explanation": subjects_data[sub]["demographics"]["diff_explanation"], "vviq_score": subjects_data[sub]["demographics"]["vviq_score"], "osiq_score": subjects_data[sub]["demographics"]["osiq_score"] }, "drawings": { "kitchen": { "perception": subjects_data[sub]["drawings"]["kitchen"]["perception"], "memory": subjects_data[sub]["drawings"]["kitchen"]["memory"] }, "livingroom": { "perception": subjects_data[sub]["drawings"]["livingroom"]["perception"], "memory": subjects_data[sub]["drawings"]["livingroom"]["memory"] }, "bedroom": { "perception": subjects_data[sub]["drawings"]["bedroom"]["perception"], "memory": subjects_data[sub]["drawings"]["bedroom"]["memory"] } }, "image": { "kitchen": subjects_data[sub]["image"]["kitchen"], "livingroom": subjects_data[sub]["image"]["livingroom"], "bedroom": subjects_data[sub]["image"]["bedroom"] } }