OS (Win10):
PsychoPy version (2025 1.1):
Standard Standalone Installation? (y
Do you want it to also run online? (n)
What are you trying to achieve?:
I am trying get an image from a csv file that I made in the builder and get it read by the image stimuli, the part I’m stuck at currently is that when I run my loop for running my training block, I get “AttributeError: Couldn’t make sense of requested image.” stopping my experiment entirely. I’ve found solutions that are basically bandaid fixes but would ultimately put me in technical dept that would solve itself if instead i figure out how to resolve the error I get.
What did you try to make it work?:
what ive been seeing on the internet for my problem ranges from builder not reading the condition in the csv file as a string to there being “invisible characters” in the condition its trying to read. I don’t know what to make of this. because using my bandaid fixes, I have gotten the routine to read the images by just manually going “$name of parameter[#]” and just making the number random with each loop. so, I have to imagine the problem is caused by how I’ve chosen to randomize the images for each run through the experiment
I made a loader loop and a routine that puts images in a folder in a csv file at the beginning of the experiment so that I am able to assign a random image for each stimuli for the entirety of the experiment
my code is as follows
BEFORE EXPERIMENT
import os
import random
import pandas as pd
BEGIN EXPERIMENT
face_list = []
face_images = []
path = "C:/Users/Em/Downloads/salienceexperiment/Publication Friendly 49-Face Database/49 Face Images"
facedb = os.listdir(path)
res = []
seen = {}
BEGIN ROUTINE
#make list of random faces
face_images.append("salienceexperiment/Publication Friendly 49-Face Database/49 Face Images/" + random.choice(facedb))
print(face_images[-1])
face_list.append(facestim)
END ROUTINE
# Iterate through the list of values (this was poached from the internet)
for ele in face_images:
# If the value has not been seen before, append it to the result list
# and add it to the dictionary
if ele not in seen:
res.append(ele)
seen[ele] = True
# If the value has been seen before, append False to the result list
else:
res.append("salienceexperiment/Publication Friendly 49-Face Database/49 Face Images/" + random.choice(facedb))
and then a routine that exists to just assign this into a csv file so it can be used in other parts of the experiment
BEGIN ROUTINE
images = {'face_list': face_list, 'face_images': face_images}
faces_stimuli = pd.DataFrame(images)
faces_stimuli.to_csv('faces_stimuli.csv', index=False)
this is where I’m trying to run it and what should be happening is that it will simply read the condition that is randomized to in the loop and all would be well, I could use other parameters in the csv file that would correspond to the current number in the list its calling so I could implement awful things like buttons and criterions and any input by participants would be recorded in a way that is nice and neat and happy. however, I get this
Traceback (most recent call last):
File “C:\Users\Emily Wang\Downloads\salienceexperiment_lastrun.py”, line 2122, in
run(
File “C:\Users\Emily Wang\Downloads\salienceexperiment_lastrun.py”, line 1325, in run
trainingfaces.setImage(face_images)
File “D:\Program Files\lib\site-packages\psychopy\visual\image.py”, line 452, in setImage
setAttribute(self, ‘image’, value, log)
File “D:\Program Files\lib\site-packages\psychopy\tools\attributetools.py”, line 191, in setAttribute
setattr(self, attrib, value)
File “D:\Program Files\lib\site-packages\psychopy\tools\attributetools.py”, line 69, in set
newValue = self.func(obj, value)
File “D:\Program Files\lib\site-packages\psychopy\visual\image.py”, line 427, in image
self.isLumImage = self._createTexture(
File “D:\Program Files\lib\site-packages\psychopy\visual\basevisual.py”, line 1103, in _createTexture
raise AttributeError(msg)
AttributeError: Couldn’t make sense of requested image.
######### Experiment ended with exit code 1 [pid:9016] #########
some strawman may say, just copy and paste the 49 names into a csv file and not have a bunch of code to make a new csv file each time, to my strawman, the file containing 49 images is placeholder, the final experiment will be sampling from a database of 10k images and you would have to pay me a stipend to do that
I’ve tried manually opening the the csv and copying out the path and entering it. It worked so that rules out it being something with how its encoded into the csv. also looked to see if there being only one condition would help. I am unsure how to go about this.
