Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'imresize' from 'scipy.misc' #45

Closed
QuickMash opened this issue Mar 12, 2024 · 2 comments
Closed

ImportError: cannot import name 'imresize' from 'scipy.misc' #45

QuickMash opened this issue Mar 12, 2024 · 2 comments

Comments

@QuickMash
Copy link

QuickMash commented Mar 12, 2024

Issue Title: ImportError: cannot import name 'imresize' from 'scipy.misc'

Description:
An exception has occurred while running create_dataset.py:
Exception has occurred: ImportError
cannot import name 'imresize' from 'scipy.misc' (c:\Users\Example\AppData\Local\Programs\Python\Python312\Lib\site-packages\scipy\misc_init_.py)
File "C:\Users\Example\OneDrive\Documents\Game-Bot-master\create_dataset.py", line 8, in
from scipy.misc import imresize
ImportError: cannot import name 'imresize' from 'scipy.misc' (c:\Users\Example\AppData\Local\Programs\Python\Python312\Lib\site-packages\scipy\misc_init_.py)
Details:

Environment: Windows
Python Version: 3.12
Package Versions:
scipy version: Unknown
scipy.misc version: Unknown
Steps to Reproduce:
Run create_dataset.py script.
Observe the ImportError.
Additional Information:
The error suggests that the name 'imresize' cannot be imported from 'scipy.misc'. This might indicate a compatibility issue or a change in the package structure. Please provide the versions of scipy and scipy.misc being used, along with any relevant information about the environment and steps to reproduce the issue.

@QuickMash
Copy link
Author

  • Forgot to fix the version

@QuickMash
Copy link
Author

I simplified the code, it opens the next files.
`# Arda Mavi

QuickMash's Fix for create_dataset.py

import os
import numpy as np
import scipy.misc
from PIL import ImageGrab
from game_control import *
import predict
from game_control import get_id
from get_dataset import save_img
from multiprocessing import Process
from keras.models import model_from_json
from pynput.mouse import Listener as mouse_listener
from pynput.keyboard import Listener as key_listener

def get_screenshot():
img = ImageGrab.grab()
img = np.array(img)[:,:,:3] # Get first 3 channel from image as numpy array.
img = imresize(img, (150, 150, 3)).astype('float32')/255.
return img

def save_event_keyboard(data_path, event, key):
key = get_id(key)
data_path = data_path + '/-1,-1,{0},{1}'.format(event, key)
screenshot = get_screenshot()
save_img(data_path, screenshot)
return

def save_event_mouse(data_path, x, y):
data_path = data_path + '/{0},{1},0,0'.format(x, y)
screenshot = get_screenshot()
save_img(data_path, screenshot)
return

def listen_mouse():
data_path = 'Data/Train_Data/Mouse'
if not os.path.exists(data_path):
os.makedirs(data_path)

def on_click(x, y, button, pressed):
    save_event_mouse(data_path, x, y)

def on_scroll(x, y, dx, dy):
    pass

def on_move(x, y):
    pass

with mouse_listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll) as listener:
    listener.join()

def listen_keyboard():
data_path = 'Data/Train_Data/Keyboard'
if not os.path.exists(data_path):
os.makedirs(data_path)

def on_press(key):
    save_event_keyboard(data_path, 1, key)

def on_release(key):
    save_event_keyboard(data_path, 2, key)

with key_listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()

def main():
dataset_path = 'Data/Train_Data/'
if not os.path.exists(dataset_path):
os.makedirs(dataset_path)

# Start to listening mouse with new process:
Process(target=listen_mouse, args=()).start()
listen_keyboard()
return

if name == 'main':
main()

QuickMash wuz here`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant