From 0eb56fb5e63b30809b6c6eb75977928cff4151bd Mon Sep 17 00:00:00 2001 From: Paul Upchurch Date: Fri, 18 May 2018 13:46:35 -0400 Subject: [PATCH 1/2] Fix "I/O operation on closed file" error --- server/normals/utils.py | 3 ++- .../management/commands/export_whitebalance_clicks.py | 3 ++- server/shapes/tasks.py | 5 +++-- server/shapes/utils.py | 9 ++++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/normals/utils.py b/server/normals/utils.py index 94829ec..2d9e6e0 100644 --- a/server/normals/utils.py +++ b/server/normals/utils.py @@ -121,7 +121,8 @@ def transform(H, points): M_ij_to_pq = linalg.inv(M_pq_to_ij) M_ij_to_pq /= M_ij_to_pq[2, 2] # NORMALIZE! data = M_ij_to_pq.ravel().tolist()[0] - image = open_image(shape.photo.image_orig) + photo = shape.photo.__class__.objects.get(id=shape.photo.id) + image = open_image(photo.image_orig) rectified = image.transform(size=size, method=Image.PERSPECTIVE, data=data, resample=Image.BICUBIC) diff --git a/server/photos/management/commands/export_whitebalance_clicks.py b/server/photos/management/commands/export_whitebalance_clicks.py index e4d4d49..cad9460 100644 --- a/server/photos/management/commands/export_whitebalance_clicks.py +++ b/server/photos/management/commands/export_whitebalance_clicks.py @@ -20,7 +20,8 @@ def handle(self, *args, **options): out = [] for label in progress.bar(qset): - pil = open_image(label.photo.image_300) + photo = label.photo.__class__.objects.get(id=label.photo.id) + pil = open_image(photo.image_300) points_list = label.points.split(',') for idx in xrange(label.num_points): x = float(points_list[idx * 2]) * pil.size[0] diff --git a/server/shapes/tasks.py b/server/shapes/tasks.py index 252e2e0..679e774 100644 --- a/server/shapes/tasks.py +++ b/server/shapes/tasks.py @@ -19,9 +19,10 @@ @shared_task def fill_in_bbox_task(shape): """ Helper to fill in the potentially empty image_bbox field """ - +. + photo = shape.photo.__class__.objects.get(id=shape.photo.id) image_bbox = mask_complex_polygon( - image=open_image(shape.photo.image_orig), + image=open_image(photo.image_orig), vertices=shape.vertices, triangles=shape.triangles, bbox_only=True) diff --git a/server/shapes/utils.py b/server/shapes/utils.py index ff3a237..9f669da 100644 --- a/server/shapes/utils.py +++ b/server/shapes/utils.py @@ -409,8 +409,9 @@ def update_shape_image_crop(shape, save=True): """ Update the cropped image for a shape """ # compute masked image + photo = shape.photo.__class__.objects.get(id=shape.photo.id) image_crop, image_bbox = mask_complex_polygon( - image=open_image(shape.photo.image_orig), + image=open_image(photo.image_orig), vertices=shape.vertices, triangles=shape.triangles) @@ -426,7 +427,8 @@ def update_shape_image_pbox(shape, padding=0.25, save=True): """ Update the pbox image for a shape """ # load image - image = open_image(shape.photo.image_orig) + photo = shape.photo.__class__.objects.get(id=shape.photo.id) + image = open_image(photo.image_orig) w, h = image.size # compute bbox @@ -677,7 +679,8 @@ def create_shape_image_sample(shape, sample_width=256, sample_height=256): if ShapeImageSample.objects.filter(shape=shape).exists(): return - image = open_image(shape.photo.image_2048) + photo = shape.photo.__class__.objects.get(id=shape.photo.id) + image = open_image(photo.image_2048) image_width, image_height = image.size triangles = parse_triangles(shape.triangles) From c93287d9fdd86b1ff9a4a20dcc2248cd232b7fe8 Mon Sep 17 00:00:00 2001 From: Paul Upchurch Date: Fri, 18 May 2018 13:50:43 -0400 Subject: [PATCH 2/2] add missing config, MTURK_CONFIGURE_QUALIFICATIONS --- server/config/settings_local_template.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/config/settings_local_template.py b/server/config/settings_local_template.py index 3ec0307..0fd8077 100644 --- a/server/config/settings_local_template.py +++ b/server/config/settings_local_template.py @@ -85,6 +85,9 @@ # debugging the POST submission. MTURK_ACCEPT_SANDBOX_HITS = False +# If True, automatically grant MTurk qualifications +MTURK_CONFIGURE_QUALIFICATIONS = False + # AWS MTurk keys if MTURK_SANDBOX: # Sandbox account