Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 숨결이 바람이 될 때
- 인생의 해상도
- Python
- 부에노비스타 소셜클럽
- Stable diffusion
- 운석 피하기 게임
- 쿠바전통음악
- 나는 스물일곱 2등 항해사입니다.
- 타이핑 몬스터
- 운석피하기 게임
- Ai
- 어른의 행복은 조용하다
- frozen lake
- pygame
- 에르난 디아스
- 매트로폴리탄
- openAI
- 타이핑좀비
- 고양이발 살인사건
- gymnasium
- 황선엽
- 트렌드코리아2025
- 타자연습게임
- 아무도 없는 숲속에서
- 나는 매트로폴리탄 미술관 경비원입니다.
- 시집
- comfyui
- 게임개발
- 단어가 품은 세계
- Gym
Archives
- Today
- Total
스푸79 기록 보관소
OpenAI Gym-FrozenLake-v1 integer argument expected, got float 오류 처리 본문
강화학습을 공부하기 위해 인터넷으로 강좌를 보면서 공부를 하던 중
예시로 나온 FrozenLake 실행을 했더니
elf_img = pygame.transform.scale(elf_img, elf_dims)
TypeError: integer argument expected, got float
위와 같은 오류가 뜨면서 동작을 하지 않았다.
큰 마음을 먹고 진득하게 공부를 시작했더니 시작부터 참...
입력값이 integer로 와야 하는데 float으로 들어오면서 오류가 발생한다는 메시지였다.
왜 동영상 강좌에서는 발생하지 않는 갈까? 혹시 강사가 mac인데 내 PC는 window라서 발생하는 건지...
아무튼 오류가 발생한 경로인
c:\Python39\lib\site-packages\gym\envs\toy_text
로 이동해서 frozen_lake.py 소스를 열고 코드를 확인해 보았다.
if self.elf_images is None:
elfs = [
path.join(path.dirname(__file__), "img/elf_left.png"),
path.join(path.dirname(__file__), "img/elf_down.png"),
path.join(path.dirname(__file__), "img/elf_right.png"),
path.join(path.dirname(__file__), "img/elf_up.png"),
]
self.elf_images = [pygame.image.load(f_name) for f_name in elfs]
board = pygame.Surface(self.window_size, flags=SRCALPHA)
cell_width = self.window_size[0] // self.ncol
cell_height = self.window_size[1] // self.nrow
smaller_cell_scale = 0.6
small_cell_w = smaller_cell_scale * cell_width
small_cell_h = smaller_cell_scale * cell_height
# prepare images
last_action = self.lastaction if self.lastaction is not None else 1
elf_img = self.elf_images[last_action]
elf_scale = min(
small_cell_w / elf_img.get_width(),
small_cell_h / elf_img.get_height(),
)
elf_dims = (
elf_img.get_width() * elf_scale,
elf_img.get_height() * elf_scale,
)
frozen_lake.py를 보니 pygame 엔진으로 개발된 것을 알 수 있었다.
pygame 엔진은 이미지 화면에 표시하는 좌표 값을 integer만 사용할 수 있다.
그런데 elf_scale, elf_dims는 연산 이후 float형으로 변환이 될 것 같은 느낌이 들었다.
혹시나 모르니 print를 코드를 넣고 오류 전에 값을 출력해 보았다.

역시나 소숫점이...
문제가 예상되는 부분을 모두 integer 형으로 변환하도록 캐스팅처리를 했다.
board = pygame.Surface(self.window_size, flags=SRCALPHA)
cell_width = self.window_size[0] // self.ncol
cell_height = self.window_size[1] // self.nrow
smaller_cell_scale = 0.6
#small_cell_w = smaller_cell_scale * cell_width
#small_cell_h = smaller_cell_scale * cell_height
#int형으로 cast 처리
small_cell_w = int(smaller_cell_scale * cell_width)
small_cell_h = int(smaller_cell_scale * cell_height)
# prepare images
last_action = self.lastaction if self.lastaction is not None else 1
elf_img = self.elf_images[last_action]
elf_scale = min(
#small_cell_w / elf_img.get_width(),
#small_cell_h / elf_img.get_height(),
#int형으로 cast 처리
int(small_cell_w / elf_img.get_width()),
int(small_cell_h / elf_img.get_height()),
)
다시 프로그램을 실행해 보면 아래와 같이 Frozen-Lake가 정상적으로 실행되는 걸 확인할 수가 있다.

'AI' 카테고리의 다른 글
FLUX 로컬 설치 방법 (+ComfyUI)-(3) 속도개선 (1) | 2024.08.13 |
---|---|
FLUX 로컬 설치 방법 (+ComfyUI)-(2) (2) | 2024.08.12 |
FLUX 로컬 설치 방법 (+ComfyUI)-(1) (6) | 2024.08.11 |
OpenAI LunarLander-v2 box2d error: command 'swig.exe' failed: None (2) | 2024.08.10 |
OpenAI Gym-FrozenLakeEnv object has no attribute lastaction 오류 처리 (2) | 2024.08.05 |