SlideShare a Scribd company logo
1 of 10
Keras: Hello World:
Installation, and
Binary Classification
by H. Shah-Hosseini
www.linkedin.com/in/dr-hamed-shah-hosseini
Keras: Hello World, by H. Shah-Hosseini 1
Prerequisite: being Familiar with Python and Scikit-learn
Keras: Preliminaries
 you should have installed one of theses as backend of keras :
 tensorflow
 cntk
 theano
 The default backend is specified in file keras.json
 ----------------------------------------------
 If you have run Keras at least once, you will find the Keras configuration file at:
 $HOME/.keras/keras.json
 ----------------------------------------------------
 If keras,json is not there, you can create it.
 NOTE for Windows Users: Please replace $HOME with %USERPROFILE%.
Keras: Hello World, by H. Shah-Hosseini 2
Keras: Preliminaries (2)
 The default configuration file ‘keras.json’ looks like this:
 {
 "image_data_format": "channels_last",
 "epsilon": 1e-07,
 "floatx": "float32",
 "backend": "tensorflow"
 }
 --------------------------------------------------------------
 You can change the field backend to "theano", "tensorflow", or "cntk“
 Then, Keras will use the new configuration, the next time you run any Keras code.
Keras: Hello World, by H. Shah-Hosseini 3
Keras: image_data_format
 image_data_format:
 it is String, either "channels_last" or "channels_first".
 It specifies which data format convention Keras will follow.
 keras.backend.image_data_format() returns the data format it uses now.
 ------------------------------------------------------------
 For 2D data (e.g. image):
 "channels_last" assumes (rows, cols, channels)
 "channels_first" assumes (channels, rows, cols)
 --------------------------------------------------------------------
 For 3D data:
 "channels_last" assumes (conv_dim1, conv_dim2, conv_dim3, channels)
 "channels_first" assumes (channels, conv_dim1, conv_dim2, conv_dim3).
 -------------------------------------------------------------------
Keras: Hello World, by H. Shah-Hosseini 4
Keras: image_data_format:
how to change in code?
 How to change defaults in program:
 >>> from keras import backend as K
 >>> K.image_data_format()
 'channels_first'
 >>> K.set_image_data_format('channels_last')
 >>> K.image_data_format()
 'channels_last'
 -------------------------
 In code above, image_data_format was ‘channels_first’, but we
changed it to ‘channels_last’
 and we checked it that it has been done correctly.
Keras: Hello World, by H. Shah-Hosseini 5
Keras: Installation
 First, you should install anaconda or Miniconda, to program in python.
 Then, if you want Keras on Theano, use at Cmd:
 conda install -c conda-forge keras
 ------------------------------
 If you want Keras on CNTK, use at Cmd:
 First, install cntk; then, install keras, like this:
 pip install <url-of-cntk>
 Pip install keras
 ---------------------
 If you want Keras on TensorFlow, use at Cmd:
 pip install tensorflow-gpu
 pip install keras
Keras: Hello World, by H. Shah-Hosseini 6
https://www.tensorflow.org/install/install_windows
https://keras.io/
https://docs.microsoft.com/en-us/cognitive-
toolkit/Setup-Windows-Python?tabs=cntkpy22
References:
Cmd=Command prompt
Keras: Installation
 Now, try the following python command in your python editor,
and if running it doesn’t not give any error, you are ok:
Keras: Hello World, by H. Shah-Hosseini 7
Keras: Binary classification
 Use BreastCancer dataset which is a
binary classification:
 ----------------------
 Model creation:
 We begin with Sequential()
 and then, we add dense (fully
connected) layers with Dense.
Keras: Hello World, by H. Shah-Hosseini 8
Keras: Binary classification (2)
 We then use compile to specify the optimization algorithm
options such the optimization method, the loss function, and
metrics:
 ---------------------------------------
 Next, we use fit to train the model:
Keras: Hello World, by H. Shah-Hosseini 9
Keras: Binary classification (3)
 To predict with the trained model, we use predict:
 -----------------------------
 Since this is classification, we must convert the vector to nearest
integer. Here, zero or one.
Keras: Hello World, by H. Shah-Hosseini 10

More Related Content

What's hot

Oracle cluster installation with grid and iscsi
Oracle cluster  installation with grid and iscsiOracle cluster  installation with grid and iscsi
Oracle cluster installation with grid and iscsiChanaka Lasantha
 
Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2IMC Institute
 
Running hadoop on ubuntu linux
Running hadoop on ubuntu linuxRunning hadoop on ubuntu linux
Running hadoop on ubuntu linuxTRCK
 
An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop InstallMike Frampton
 
Hadoop single cluster installation
Hadoop single cluster installationHadoop single cluster installation
Hadoop single cluster installationMinh Tran
 
Ansible Network Automation session1
Ansible Network Automation session1Ansible Network Automation session1
Ansible Network Automation session1Dhruv Sharma
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced ReplicationMongoDB
 
Docker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in PragueDocker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in Praguetomasbart
 
Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Denish Patel
 
Hadoop single node setup
Hadoop single node setupHadoop single node setup
Hadoop single node setupMohammad_Tariq
 
Single node hadoop cluster installation
Single node hadoop cluster installation Single node hadoop cluster installation
Single node hadoop cluster installation Mahantesh Angadi
 
Lamp configuration u buntu 10.04
Lamp configuration   u buntu 10.04Lamp configuration   u buntu 10.04
Lamp configuration u buntu 10.04mikehie
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...VCP Muthukrishna
 
Squid proxy-configuration-guide
Squid proxy-configuration-guideSquid proxy-configuration-guide
Squid proxy-configuration-guidejasembo
 
Postgres-BDR with Google Cloud Platform
Postgres-BDR with Google Cloud PlatformPostgres-BDR with Google Cloud Platform
Postgres-BDR with Google Cloud PlatformSungJae Yun
 

What's hot (20)

Oracle cluster installation with grid and iscsi
Oracle cluster  installation with grid and iscsiOracle cluster  installation with grid and iscsi
Oracle cluster installation with grid and iscsi
 
Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2
 
Running hadoop on ubuntu linux
Running hadoop on ubuntu linuxRunning hadoop on ubuntu linux
Running hadoop on ubuntu linux
 
An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop Install
 
Hadoop single cluster installation
Hadoop single cluster installationHadoop single cluster installation
Hadoop single cluster installation
 
Ansible Network Automation session1
Ansible Network Automation session1Ansible Network Automation session1
Ansible Network Automation session1
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
Docker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in PragueDocker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in Prague
 
Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)
 
Ex407
Ex407Ex407
Ex407
 
Hadoop single node setup
Hadoop single node setupHadoop single node setup
Hadoop single node setup
 
Squid Server
Squid ServerSquid Server
Squid Server
 
Kickstart
KickstartKickstart
Kickstart
 
Single node hadoop cluster installation
Single node hadoop cluster installation Single node hadoop cluster installation
Single node hadoop cluster installation
 
Lamp configuration u buntu 10.04
Lamp configuration   u buntu 10.04Lamp configuration   u buntu 10.04
Lamp configuration u buntu 10.04
 
Dhcp
DhcpDhcp
Dhcp
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
 
Squid proxy-configuration-guide
Squid proxy-configuration-guideSquid proxy-configuration-guide
Squid proxy-configuration-guide
 
Postgres-BDR with Google Cloud Platform
Postgres-BDR with Google Cloud PlatformPostgres-BDR with Google Cloud Platform
Postgres-BDR with Google Cloud Platform
 
Installing lemp with ssl and varnish on Debian 9
Installing lemp with ssl and varnish on Debian 9Installing lemp with ssl and varnish on Debian 9
Installing lemp with ssl and varnish on Debian 9
 

Similar to Python, Keras, Hello world, Installation, Binary Classification

Snort296x centos6x 2
Snort296x centos6x 2Snort296x centos6x 2
Snort296x centos6x 2Trinh Tuan
 
Docker container management
Docker container managementDocker container management
Docker container managementKarol Kreft
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopLorin Hochstein
 
Project 2 how to install and compile os161
Project 2 how to install and compile os161Project 2 how to install and compile os161
Project 2 how to install and compile os161Xiao Qin
 
55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines55 best linux tips, tricks and command lines
55 best linux tips, tricks and command linesArif Wahyudi
 
Automatic systems installations and change management wit FAI - Talk for Netw...
Automatic systems installations and change management wit FAI - Talk for Netw...Automatic systems installations and change management wit FAI - Talk for Netw...
Automatic systems installations and change management wit FAI - Talk for Netw...Henning Sprang
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configurationSubhas Kumar Ghosh
 
Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14jijukjoseph
 
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库maclean liu
 
Oracle 11g R2 RAC setup on rhel 5.0
Oracle 11g R2 RAC setup on rhel 5.0Oracle 11g R2 RAC setup on rhel 5.0
Oracle 11g R2 RAC setup on rhel 5.0Santosh Kangane
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierCarlos Sanchez
 
在Oel5上安装配置oracle gird control 10.2.0.5
在Oel5上安装配置oracle gird control 10.2.0.5在Oel5上安装配置oracle gird control 10.2.0.5
在Oel5上安装配置oracle gird control 10.2.0.5maclean liu
 

Similar to Python, Keras, Hello world, Installation, Binary Classification (20)

Snort296x centos6x 2
Snort296x centos6x 2Snort296x centos6x 2
Snort296x centos6x 2
 
Rac on NFS
Rac on NFSRac on NFS
Rac on NFS
 
Docker container management
Docker container managementDocker container management
Docker container management
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
Ass OS
Ass OSAss OS
Ass OS
 
Ass hđh
Ass hđhAss hđh
Ass hđh
 
Project 2 how to install and compile os161
Project 2 how to install and compile os161Project 2 how to install and compile os161
Project 2 how to install and compile os161
 
Arch Linux Cheat
Arch Linux CheatArch Linux Cheat
Arch Linux Cheat
 
55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines
 
Automatic systems installations and change management wit FAI - Talk for Netw...
Automatic systems installations and change management wit FAI - Talk for Netw...Automatic systems installations and change management wit FAI - Talk for Netw...
Automatic systems installations and change management wit FAI - Talk for Netw...
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configuration
 
Linux configer
Linux configerLinux configer
Linux configer
 
Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14
 
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
 
Oracle 11g R2 RAC setup on rhel 5.0
Oracle 11g R2 RAC setup on rhel 5.0Oracle 11g R2 RAC setup on rhel 5.0
Oracle 11g R2 RAC setup on rhel 5.0
 
RDO-Packstack Workshop
RDO-Packstack Workshop RDO-Packstack Workshop
RDO-Packstack Workshop
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Docker practice
Docker practiceDocker practice
Docker practice
 
在Oel5上安装配置oracle gird control 10.2.0.5
在Oel5上安装配置oracle gird control 10.2.0.5在Oel5上安装配置oracle gird control 10.2.0.5
在Oel5上安装配置oracle gird control 10.2.0.5
 
Linux
LinuxLinux
Linux
 

Recently uploaded

POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.Silpa
 
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...Scintica Instrumentation
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY1301aanya
 
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRingsTransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRingsSérgio Sacani
 
Genetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsGenetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsbassianu17
 
Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.Silpa
 
Use of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxUse of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxRenuJangid3
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .Poonam Aher Patil
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.Silpa
 
Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.Silpa
 
FAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceFAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceAlex Henderson
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Silpa
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxSuji236384
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxSilpa
 
Grade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsGrade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsOrtegaSyrineMay
 
Cyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptxCyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptxSilpa
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Silpa
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusNazaninKarimi6
 

Recently uploaded (20)

POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
 
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY
 
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRingsTransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
 
Genetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsGenetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditions
 
Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.Reboulia: features, anatomy, morphology etc.
Reboulia: features, anatomy, morphology etc.
 
Use of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxUse of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptx
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.
 
Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.Phenolics: types, biosynthesis and functions.
Phenolics: types, biosynthesis and functions.
 
FAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceFAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical Science
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
 
Site Acceptance Test .
Site Acceptance Test                    .Site Acceptance Test                    .
Site Acceptance Test .
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptx
 
Grade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsGrade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its Functions
 
Cyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptxCyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptx
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
 

Python, Keras, Hello world, Installation, Binary Classification

  • 1. Keras: Hello World: Installation, and Binary Classification by H. Shah-Hosseini www.linkedin.com/in/dr-hamed-shah-hosseini Keras: Hello World, by H. Shah-Hosseini 1 Prerequisite: being Familiar with Python and Scikit-learn
  • 2. Keras: Preliminaries  you should have installed one of theses as backend of keras :  tensorflow  cntk  theano  The default backend is specified in file keras.json  ----------------------------------------------  If you have run Keras at least once, you will find the Keras configuration file at:  $HOME/.keras/keras.json  ----------------------------------------------------  If keras,json is not there, you can create it.  NOTE for Windows Users: Please replace $HOME with %USERPROFILE%. Keras: Hello World, by H. Shah-Hosseini 2
  • 3. Keras: Preliminaries (2)  The default configuration file ‘keras.json’ looks like this:  {  "image_data_format": "channels_last",  "epsilon": 1e-07,  "floatx": "float32",  "backend": "tensorflow"  }  --------------------------------------------------------------  You can change the field backend to "theano", "tensorflow", or "cntk“  Then, Keras will use the new configuration, the next time you run any Keras code. Keras: Hello World, by H. Shah-Hosseini 3
  • 4. Keras: image_data_format  image_data_format:  it is String, either "channels_last" or "channels_first".  It specifies which data format convention Keras will follow.  keras.backend.image_data_format() returns the data format it uses now.  ------------------------------------------------------------  For 2D data (e.g. image):  "channels_last" assumes (rows, cols, channels)  "channels_first" assumes (channels, rows, cols)  --------------------------------------------------------------------  For 3D data:  "channels_last" assumes (conv_dim1, conv_dim2, conv_dim3, channels)  "channels_first" assumes (channels, conv_dim1, conv_dim2, conv_dim3).  ------------------------------------------------------------------- Keras: Hello World, by H. Shah-Hosseini 4
  • 5. Keras: image_data_format: how to change in code?  How to change defaults in program:  >>> from keras import backend as K  >>> K.image_data_format()  'channels_first'  >>> K.set_image_data_format('channels_last')  >>> K.image_data_format()  'channels_last'  -------------------------  In code above, image_data_format was ‘channels_first’, but we changed it to ‘channels_last’  and we checked it that it has been done correctly. Keras: Hello World, by H. Shah-Hosseini 5
  • 6. Keras: Installation  First, you should install anaconda or Miniconda, to program in python.  Then, if you want Keras on Theano, use at Cmd:  conda install -c conda-forge keras  ------------------------------  If you want Keras on CNTK, use at Cmd:  First, install cntk; then, install keras, like this:  pip install <url-of-cntk>  Pip install keras  ---------------------  If you want Keras on TensorFlow, use at Cmd:  pip install tensorflow-gpu  pip install keras Keras: Hello World, by H. Shah-Hosseini 6 https://www.tensorflow.org/install/install_windows https://keras.io/ https://docs.microsoft.com/en-us/cognitive- toolkit/Setup-Windows-Python?tabs=cntkpy22 References: Cmd=Command prompt
  • 7. Keras: Installation  Now, try the following python command in your python editor, and if running it doesn’t not give any error, you are ok: Keras: Hello World, by H. Shah-Hosseini 7
  • 8. Keras: Binary classification  Use BreastCancer dataset which is a binary classification:  ----------------------  Model creation:  We begin with Sequential()  and then, we add dense (fully connected) layers with Dense. Keras: Hello World, by H. Shah-Hosseini 8
  • 9. Keras: Binary classification (2)  We then use compile to specify the optimization algorithm options such the optimization method, the loss function, and metrics:  ---------------------------------------  Next, we use fit to train the model: Keras: Hello World, by H. Shah-Hosseini 9
  • 10. Keras: Binary classification (3)  To predict with the trained model, we use predict:  -----------------------------  Since this is classification, we must convert the vector to nearest integer. Here, zero or one. Keras: Hello World, by H. Shah-Hosseini 10