Skip to content

Commit 7065009

Browse files
committed
Replaced deprecated scipy image-resize with PIL.
1 parent aa0d679 commit 7065009

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

reinforcement_learning.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
import numpy as np
159159
import tensorflow as tf
160160
import gym
161-
import scipy
161+
import PIL.Image
162162
import sys
163163
import os
164164
import time
@@ -405,6 +405,9 @@ def print_progress(msg):
405405
# Size of each image in the state.
406406
state_img_size = np.array([state_height, state_width])
407407

408+
# Size of each image in the state. Reversed order used by PIL.Image.
409+
state_img_size_reverse = tuple(reversed(state_img_size))
410+
408411
# Number of images in the state.
409412
state_channels = 2
410413

@@ -435,12 +438,19 @@ def _pre_process_image(image):
435438
"""Pre-process a raw image from the game-environment."""
436439

437440
# Convert image to gray-scale.
438-
img = _rgb_to_grayscale(image)
441+
img_gray = _rgb_to_grayscale(image=image)
442+
443+
# Create PIL-object from numpy array.
444+
img = PIL.Image.fromarray(img_gray)
445+
446+
# Resize the image.
447+
img_resized = img.resize(size=state_img_size_reverse,
448+
resample=PIL.Image.LINEAR)
439449

440-
# Resize to the desired size using SciPy for convenience.
441-
img = scipy.misc.imresize(img, size=state_img_size, interp='bicubic')
450+
# Convert 8-bit pixel values back to floating-point.
451+
img_resized = np.float32(img_resized)
442452

443-
return img
453+
return img_resized
444454

445455

446456
class MotionTracer:

0 commit comments

Comments
 (0)