Cov txheej txheem:

Pob Zeb Txiab Txiab AI: 11 Kauj Ruam
Pob Zeb Txiab Txiab AI: 11 Kauj Ruam

Video: Pob Zeb Txiab Txiab AI: 11 Kauj Ruam

Video: Pob Zeb Txiab Txiab AI: 11 Kauj Ruam
Video: coj daim duab pob zeb mus lo pem pob zeb vaj ntxa 10 11 2021 2024, Hlis ntuj nqeg
Anonim
Pob Zeb Txiab Txiab AI
Pob Zeb Txiab Txiab AI

Puas tau hnov qab ib leeg? Wb ua si pob zeb, ntawv, thiab txiab tawm tsam qhov kev sib tham sib txhawb nrog kev txawj ntse.

Kauj Ruam 1: Yam Khoom Siv Hauv Txoj Haujlwm no

Cov khoom siv kho vajtse

  • Raspberry Pi 3 Qauv B+ × 1
  • Raspberry Pi Lub Koob Yees Duab Module V2 × 1
  • SG90 Micro-servo motor × 1

Cov software software

  • Raspberry Pi Raspbian
  • QhibCV
  • TensorFlow

Kauj ruam 2: Tswv yim?

Image
Image

Tom qab ua haujlwm ntawm ntau txoj haujlwm ntawm ntau qhov sib txawv, Kuv tau npaj ua qhov haujlwm lom zem, thiab kuv txiav txim siab ua pob zeb-ntawv-txiab game:)

Hauv txoj haujlwm no, peb yuav ua kev sib tham sib tham thiab ua si tawm tsam lub khoos phis tawj uas tau siv los ntawm AI los txiav txim siab. AI siv Lub Koob Yees Duab txuas nrog Raspberry Pi kom paub txog qhov txav tus neeg siv ua nrog tes, cais lawv mus rau qeb zoo tshaj plaws (daim ntawv lo) pob zeb, ntawv, lossis txiab. Thaum lub khoos phis tawj ua rau nws txav mus, lub tshuab hluav taws xob txuas nrog rau Raspberry Pi cov ntsiab lus ntawm kev taw qhia raws li nws txav mus.

Cov cai uas yuav tsum tau txiav txim siab rau qhov kev ua si no:

  • Pob zeb blunts tus txiab
  • Ntawv npog lub pob zeb
  • Txiab txiav ntawv

Tus yeej yuav raug txiav txim siab raws li peb qhov xwm txheej saum toj no. Cia peb pom qhov nrawm ntawm qhov haujlwm ntawm no.

Kauj ruam 3: Pib?

Pib Pib?
Pib Pib?
Pib Pib?
Pib Pib?

Raspberry Pi

Kuv tau siv Raspberry Pi 3 Qauv B+ uas muaj kev txhim kho zoo thiab muaj zog dua li yav dhau los Raspberry Pi 3 Qauv B.

Raspberry Pi 3 B+ tau koom ua ke nrog 1.4GHz 64-ntsis plaub-core processor, dual-band wireless LAN, Bluetooth 4.2/BLE, sai dua Ethernet, thiab Kev txhawb zog-dhau-Ethernet (nrog cais PoE HAT).

Kev qhia tshwj xeeb: Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-ntsis SoC @ 1.4GHz, 1GB LPDDR2 SDRAM, 2.4GHz thiab 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE, Gigabit Ethernet hla USB 2.0 (qhov siab tshaj ntawm 300 Mbps), Txuas ntxiv 40-pin GPIO header, Full-size HDMI4 USB 2.0 chaw nres nkoj, CSI lub koob yees duab chaw nres nkoj rau txuas lub Raspberry Pi lub koob yees duab, DSI zaub chaw nres nkoj rau txuas Raspberry Pi touchscreen display4-ncej tso suab tso zis thiab sib xyaw video chaw nres nkoj, Micro SD chaw nres nkoj rau thauj koj lub operating system thiab khaws cov ntaub ntawv 5V/2.5A DC lub zog siv hluav taws xob, Kev txhawb zog-dhau-Ethernet (PoE) txhawb nqa (xav tau cais PoE HAT).

Servo Tsav

Peb siv SG-90 servo motor, lub cev muaj zog loj uas tuaj yeem tswj lub nra mus txog 2.5kg (1cm).

USB Lub Koob Yees Duab

Lub koob yees duab USB los ua qhov kev sib tham sib tham nrog kev ua cov duab

Qee lub Jumper cables tau siv los xaim lub tshuab tsav tsheb thiab Raspberry Pi.

Kauj Ruam 4: Hlawv Raspbian rau SD Card?

Hlawv Raspbian rau SD Card?
Hlawv Raspbian rau SD Card?
Hlawv Raspbian rau SD Card?
Hlawv Raspbian rau SD Card?
Hlawv Raspbian rau SD Card?
Hlawv Raspbian rau SD Card?

Raspbian yog Linux faib kev xaiv khiav ntawm Raspberry Pi. Hauv phau ntawv qhia no, peb yuav siv Lite version, tab sis Desktop version (uas los nrog cov duab ib puag ncig) tuaj yeem siv tau ib yam.

  • Rub tawm Etcher thiab nruab nws.
  • Txuas tus nyeem daim npav SD nrog daim npav SD sab hauv.
  • Qhib Etcher thiab xaiv los ntawm koj lub hard drive Raspberry Pi.img lossis.zip cov ntaub ntawv koj xav sau rau SD daim npav.
  • Xaiv daim npav SD koj xav sau koj daim duab rau.
  • Txheeb xyuas koj cov kev xaiv thiab nyem 'Flash!' pib sau cov ntaub ntawv rau SD daim npav.

Txuas lub cuab yeej rau koj lub network

  • Pab kom SSH nkag los ntawm kev ntxiv cov ntaub ntawv khoob ssh, rov tso rau ntawm lub hauv paus ntawm lub ntim ntim ntawm koj daim npav SD.
  • Ntxig daim npav SD rau hauv Raspberry Pi. Nws yuav khau raj kwv yees li 20 vib nas this. Tam sim no koj yuav tsum muaj SSH nkag mus rau koj li Raspberry Pi. Los ntawm lub neej ntawd, nws lub npe host yuav raspberrypi.local. Hauv koj lub khoos phis tawj, qhib lub qhov rai qhib thiab ntaus cov hauv qab no:

ssh [email protected]

Tus password tsis raug yog raspberry

Ntawm no kuv tau siv tus saib cais los cuam tshuam nrog Raspberry Pi.

Kauj Ruam 5: Sau Cov Ntaub Ntawv? ️

Sau Cov Ntaub Ntawv? ️
Sau Cov Ntaub Ntawv? ️
Sau Cov Ntaub Ntawv? ️
Sau Cov Ntaub Ntawv? ️

Thawj kauj ruam hauv txoj haujlwm no yog khaws cov ntaub ntawv. Lub kaw lus yuav tsum txheeb xyuas cov tes taw thiab lees paub qhov kev nqis tes ua thiab ua kom nws txav mus raws qhov ntawd.

Peb teeb tsa ntau lub tsev qiv ntawv rau Raspberry Pi siv pip nruab

hais kom ua

sudo apt-tau hloov tshiab && sudo apt-tau hloov dua tshiab apt-tau nruab libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev pip nruab opencv pip nruab numpy pip nruab scikit-kawm pip nruab scikit-duab pip nruab h5py pip nruab Keras pip install tensorflow pip install Werkzeug pip install Keras-Applications pip install Keras-Preprocessing pip install keras-squeezenet pip install astor pip install tenorboard pip install tensorflow-Estator pip install mock pip install grpcio pip install absl-pypip install gast pip install joblib pip install Markdown pip nruab protobuf pip nruab PyYAML pip nruab rau

Yog tias koj ntsib teeb meem nrog OpenCVpackage, Kuv pom zoo kom txhim kho cov pob khoom no.

sudo apt-tau nruab libhdf5-dev

sudo apt-tau nruab libhdf5-serial-dev sudo apt-tau nruab libatlas-puag-dev sudo apt-tau nruab libjasper-dev sudo apt-tau nruab libqtgui4 sudo apt-tau nruab libqt4-xeem

Peb tau teeb tsa txhua qhov xav tau kev vam khom rau txoj haujlwm no. Cov Ntaub Ntawv-teeb tsa yog tsim los ntawm kev sau thiab npaj cov duab hauv qab daim ntawv tsim nyog.

Ntawm no peb tsim cov ntaub ntawv teeb duab rau daim ntawv lo pob zeb, ntawv thiab txiab siv cov ntawv hauv qab no.

roi = thav duab [100: 500, 100: 500]

save_path = os.path.join (img_class_path, '{}.jpg'.format (suav + 1)) cv2.imwrite (save_path, roi)

Cov duab raug ntes rau txhua daim ntawv lo (pob zeb, ntawv, txiab thiab Tsis muaj).

Kauj Ruam 6: Tsim NN & Qhia Tus Qauv ⚒️⚙️

Tsim NN & Qhia Tus Qauv ⚒️⚙️
Tsim NN & Qhia Tus Qauv ⚒️⚙️

Cov Tub Ntxhais ntawm txoj haujlwm no yog cov duab sib cais uas cais ib ntawm peb pawg. Txhawm rau ua Tus Txheeb cais no, peb siv kev kawm ua ntej CNN (Kev Sib Koom Network) hu ua SqueezeNet.

Ntawm no peb siv Keras thiab TensorFlow los tsim tus qauv SqueezeNet uas tuaj yeem txheeb xyuas tus taw. Cov duab uas peb tsim tawm hauv cov kauj ruam dhau los yog siv los qhia tus qauv. Tus qauv yog kawm paub siv Dataset tsim rau tsis muaj Epochs (Cycles) hais.

Tus qauv tau teeb tsa nrog cov ntsuas siab raws li qhia hauv qab no.

qauv = Sequential ([SqueezeNet (input_shape = (227, 227, 3), include_top = Tsis tseeb), Tawm (0.5), Convolution2D (NUM_CLASSES, (1, 1), padding = 'siv tau'), Qhib ('relu'), GlobalAveragePooling2D (), Qhib ('softmax')])

Thaum tus qauv raug cob qhia, koj tuaj yeem pom qhov poob thiab qhov raug ntawm tus qauv rau txhua Lub Sijhawm thiab qhov tseeb nce nyob rau qee lub sijhawm tom qab ob peb Epoch.

Nws siv sijhawm kwv yees li 2 teev los tsim cov qauv nrog qhov raug siab tshaj plaws tom qab 10 lub sijhawm. Yog tias koj ntsib ib qho kev faib khoom tsis raug, ua cov theem hauv qab no (Ua tsaug rau Adrian)

Txhawm rau nce koj qhov chaw sib pauv, qhib /etc /dphys-swapfile thiab tom qab ntawd hloov kho CONF_SWAPSIZE sib txawv:

# CONF_SWAPSIZE = 100

SIB = 1024

Daim ntawv ceeb toom tias kuv nce kev sib pauv los ntawm 100MB txog 1024MB. Los ntawm qhov ntawd, rov pib dua qhov kev pabcuam sib pauv:

$ sudo /etc/init.d/dphys-swapfile nres

$ sudo /etc/init.d/dphys-swapfile pib

Nco tseg:

Kev nce qhov sib pauv me me yog txoj hauv kev zoo los hlawv koj daim npav nco, yog li nco ntsoov rov thim qhov kev hloov pauv no thiab rov pib ua haujlwm sib pauv thaum koj ua tiav. Koj tuaj yeem nyeem ntxiv txog qhov loj me me ua rau daim npav nco tsis zoo ntawm no.

Kauj Ruam 7: Xeem Tus Qauv ✅

Xeem Cov Qauv ✅
Xeem Cov Qauv ✅
Xeem Cov Qauv ✅
Xeem Cov Qauv ✅
Xeem Cov Qauv ✅
Xeem Cov Qauv ✅

Thaum tus qauv raug tsim, Nws tsim cov ntaub ntawv tso tawm "pob zeb-ntawv-txiab-qauv.h5". Cov ntaub ntawv no tau siv los ua lub hauv paus los ntsuas seb lub kaw lus tuaj yeem txheeb xyuas cov tes taw sib txawv thiab tuaj yeem sib txawv ntawm qhov ua.

Tus qauv raug thauj khoom hauv kab ntawv nab hab sej raws li hauv qab no

qauv = load_model ("pob zeb-ntawv-txiab-qauv.h5")

Lub koob yees duab nyeem cov duab ntsuas thiab hloov pauv tus qauv xim uas xav tau, thiab tom qab ntawd hloov qhov duab rau 227 x 227 pixel (Tib qhov loj siv rau kev tsim qauv). Cov duab uas tau siv rau kev qhia tus qauv tuaj yeem siv los ntsuas cov qauv tsim.

img = cv2.imread (kab ntawv kab ntawv)

img = cv2.cvtColor (img, cv2. COLOR_BGR2RGB) img = cv2.resize (img, (227, 227))

Thaum tus qauv raug thauj khoom thiab cov duab tau txais los ntawm lub koob yees duab, tus qauv kwv yees cov duab uas siv los ntawm SqueezeNet tus qauv thauj khoom, thiab ua qhov twv ua ntej rau tus neeg siv txav.

pred = model.predict (np.array ())

move_code = np.argmax (pred [0]) move_name = mapper (move_code) print ("Kwv yees: {}". format (move_name))

Khiav test.py tsab ntawv los ntsuas tus qauv nrog ntau yam duab ntsuas.

sej 3 test.py

Tam sim no tus qauv tau npaj los tshuaj xyuas thiab nkag siab txhais tes.

Kauj Ruam 8: Pob Zeb-Ntawv-Txiab Game

Pob Zeb-Ntawv-Txiab Game
Pob Zeb-Ntawv-Txiab Game

Qhov Kev Ua Si siv tus lej lej ua haujlwm tsis zoo los txiav txim siab kho lub computer. Nws ua raws cov cai hais los saum toj no los txiav txim siab tus yeej. Qhov kev ua si yog tsim los nrog ob hom: Hom Ib txwm thiab Hom Ntsej Muag, qhov twg hom ntse tiv thaiv tus neeg siv lub zog, piv txwv li Khoos phis tawj yeej txhua qhov kev tawm tsam rau tus neeg siv.

cap = cv2. VideoCapture (0) # Txhawm rau ntes cov duab los ntawm Lub Koob Yees Duab

Tam sim no cia ua qhov kev ua si hauv Hom Ib txwm nyob qhov twg qhov system/ Raspberry Pi siv daim duab ntawm tes thiab tshuaj xyuas thiab txheeb xyuas tus tes taw. Tom qab ntawd siv lub tshuab hluav taws xob tus lej tsis raug, lub computer txav mus. Tus yeej yog xaiv raws txoj cai thiab tom qab ntawd tso tawm ntawm qhov screen. Pib qhov kev ua si siv cov lus txib hauv qab no.

python3 play.py

Kauj Ruam 9: Kev Sib Koom Tsav Tsheb?

Thaum kawg, ntxiv servo motor rau txoj haujlwm no. Servo motor yog GPIO tus pin 17 ntawm Raspberry Pi, uas muaj PWM ua haujlwm los tswj lub kaum sab xis ntawm kev sib hloov.

Servo Motor siv hauv txoj haujlwm no yog SG-90. Nws tuaj yeem ua kev sib hloov raws clockwise thiab anti-clockwise txog 180 °

Cov Kev Sib Txuas tau muab raws li hauv qab no.

Servo Tsav - Raspberry Pi

Vcc - +5V

GND - NCO

Teeb liab - GPIO17

Cov tsev qiv ntawv xws li RPi. GPIO thiab sijhawm tau siv hauv txoj haujlwm no.

ntshuam RPi. GPIO ua GPIO

lub sij hawm ntshuam

GPIO tus pin yog tom qab teeb tsa rau PWM siv cov kab hauv qab no

servoPIN = 17

GPIO.setmode (GPIO. BCM) GPIO.setup (servoPIN, GPIO. OUT)

GPIO Pin 17 tau teeb tsa los siv ua PWM ntawm qhov zaus ntawm 50Hz. Lub kaum sab xis ntawm servo motor tau ua tiav los ntawm kev teeb tsa lub luag haujlwm (Ton & Toff) ntawm PWM

luag = kaum/18 + 2

GPIO.output (servoPIN, True) p. ChangeDutyCycle (lub luag haujlwm) time.sleep (1) GPIO.output (servoPIN, False) p. ChangeDutyCycle (0)

Qhov no yuav tsim lub kaum sab xis xav tau rau txhua tus mem tes, uas yuav muab lub kaum sab xis ntawm kev sib hloov.

Tam sim no kuv tau coj daim duab thiab txiav nws ua peb ntu, rau pob zeb, ntawv, thiab txiab. Lub Servo lub cev muaj zog tau tsau rau hauv nruab nrab ntawm daim duab. Tus taw tes/nrov plig plawg txuas nrog lub ncej ntawm servo motor. Cov ncej no taw qhia rau lub khoos phis tawj txav mus raws li cov laj thawj suav hauv tsab ntawv.

Kauj ruam 10: Ua haujlwm ntawm Txoj Haujlwm?

Image
Image

Thiab tam sim no, nws yog lub sijhawm ua si. Cia peb pom txoj haujlwm ntawm txoj haujlwm.

Yog tias koj ntsib teeb meem hauv kev tsim txoj haujlwm no, thov hu rau kuv. Thov qhia cov haujlwm tshiab uas koj xav kom kuv ua tom ntej.

Muab tus ntiv tes xoo yog tias nws tau pab koj tiag tiag thiab ua raws kuv li channel rau cov phiaj xwm txaus nyiam.:)

Muab daim vis dis aus no yog koj nyiam.

Zoo siab uas koj tau sau npe:

Ua tsaug rau kev nyeem ntawv!

Kauj ruam 11: Code - Project Repo

Cov cai tau ntxiv rau GitHub Cov Chaw khaws khoom uas tuaj yeem pom hauv ntu kab ntawv.

Rahul24-06/Pob Zeb-Ntawv-Txiab-https://github.com/Rahul24-06/Rock-Paper-Scissors

Pom zoo: