Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2021-210
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-210
2021-210
Commits
0c71a422
Commit
0c71a422
authored
Jul 05, 2021
by
Saluk Bawantha
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'IT18124354_SALUKB.M.M' into 'master'
Create Model See merge request
!13
parents
a573d2fd
7760321d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
148 additions
and
0 deletions
+148
-0
skin_disease/.gitignore
skin_disease/.gitignore
+3
-0
skin_disease/convolutional_neural_network.py
skin_disease/convolutional_neural_network.py
+72
-0
skin_disease/predict_image_class.py
skin_disease/predict_image_class.py
+73
-0
No files found.
skin_disease/.gitignore
0 → 100644
View file @
0c71a422
.idea
data
model_saved.h5
\ No newline at end of file
skin_disease/convolutional_neural_network.py
0 → 100644
View file @
0c71a422
# importing libraries
import
keras
,
tensorflow
import
numpy
as
np
from
keras.preprocessing.image
import
ImageDataGenerator
from
keras.models
import
Sequential
from
keras.layers
import
Conv2D
,
MaxPooling2D
from
keras.layers
import
Activation
,
Dropout
,
Flatten
,
Dense
from
keras
import
backend
as
K
img_width
,
img_height
=
350
,
350
train_data_dir
=
'data/train'
validation_data_dir
=
'data/test'
nb_train_samples
=
168
nb_validation_samples
=
20
epochs
=
20
batch_size
=
20
if
K
.
image_data_format
()
==
'channels_first'
:
input_shape
=
(
3
,
img_width
,
img_height
)
else
:
input_shape
=
(
img_width
,
img_height
,
3
)
model
=
Sequential
()
model
.
add
(
Conv2D
(
32
,
(
2
,
2
),
input_shape
=
input_shape
))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
model
.
add
(
Conv2D
(
32
,
(
2
,
2
)))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
model
.
add
(
Conv2D
(
64
,
(
2
,
2
)))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
model
.
add
(
Flatten
())
model
.
add
(
Dense
(
64
))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
Dropout
(
0.5
))
model
.
add
(
Dense
(
2
))
model
.
add
(
Activation
(
'softmax'
))
model
.
compile
(
loss
=
'sparse_categorical_crossentropy'
,
optimizer
=
'adam'
,
metrics
=
[
'accuracy'
])
train_datagen
=
ImageDataGenerator
(
rescale
=
1.
/
255
,
shear_range
=
0.2
,
zoom_range
=
0.2
,
horizontal_flip
=
True
)
test_datagen
=
ImageDataGenerator
(
rescale
=
1.
/
255
)
train_generator
=
train_datagen
.
flow_from_directory
(
train_data_dir
,
target_size
=
(
img_width
,
img_height
),
batch_size
=
batch_size
,
class_mode
=
'sparse'
)
validation_generator
=
test_datagen
.
flow_from_directory
(
validation_data_dir
,
target_size
=
(
img_width
,
img_height
),
batch_size
=
batch_size
,
class_mode
=
'sparse'
)
model
.
fit_generator
(
train_generator
,
steps_per_epoch
=
nb_train_samples
//
batch_size
,
epochs
=
epochs
,
validation_data
=
validation_generator
,
validation_steps
=
nb_validation_samples
//
batch_size
)
model
.
save_weights
(
'model_saved.h5'
)
skin_disease/predict_image_class.py
0 → 100644
View file @
0c71a422
from
keras.layers
import
Activation
import
keras
import
numpy
as
np
import
tensorflow
from
keras
import
backend
as
K
from
keras.layers
import
Activation
from
keras.layers
import
Conv2D
,
MaxPooling2D
from
keras.layers
import
Dense
,
Dropout
,
Flatten
from
keras.models
import
Sequential
print
(
tensorflow
.
__version__
)
print
(
keras
.
__version__
)
def
predictImageClass
(
image
):
K
.
clear_session
()
tensorflow
.
reset_default_graph
()
nb_train_samples
=
112
nb_validation_samples
=
20
epochs
=
10
batch_size
=
2
img_width
,
img_height
=
350
,
350
if
K
.
image_data_format
()
==
'channels_first'
:
input_shape
=
(
3
,
img_width
,
img_height
)
else
:
input_shape
=
(
img_width
,
img_height
,
3
)
modelI
=
Sequential
()
modelI
.
add
(
Conv2D
(
32
,
(
2
,
2
),
input_shape
=
input_shape
))
modelI
.
add
(
Activation
(
'relu'
))
modelI
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
modelI
.
add
(
Conv2D
(
32
,
(
2
,
2
)))
modelI
.
add
(
Activation
(
'relu'
))
modelI
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
modelI
.
add
(
Conv2D
(
64
,
(
2
,
2
)))
modelI
.
add
(
Activation
(
'relu'
))
modelI
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
modelI
.
add
(
Flatten
())
modelI
.
add
(
Dense
(
64
))
modelI
.
add
(
Activation
(
'relu'
))
modelI
.
add
(
Dropout
(
0.5
))
modelI
.
add
(
Dense
(
2
))
modelI
.
add
(
Activation
(
'softmax'
))
modelI
.
compile
(
loss
=
'sparse_categorical_crossentropy'
,
optimizer
=
'adam'
,
metrics
=
[
'accuracy'
])
modelI
.
load_weights
(
'model_saved.h5'
)
sess
=
keras
.
backend
.
get_session
()
# image = request.args.get('image', default = 1, type = str)
print
(
"------------------"
)
print
(
image
)
print
(
"------------------"
)
img
=
tensorflow
.
read_file
(
image
)
img
=
tensorflow
.
image
.
decode_jpeg
(
img
,
channels
=
3
)
img
.
set_shape
([
None
,
None
,
3
])
img
=
tensorflow
.
image
.
resize_images
(
img
,
(
350
,
350
))
img
=
img
.
eval
(
session
=
sess
)
# convert to numpy array
img
=
np
.
expand_dims
(
img
,
0
)
# make 'batch' of 1
pred
=
modelI
.
predict
(
img
)
# pred = labels["label_names"][np.argmax(pred)]
print
(
pred
)
y
=
[
"Ring worms"
,
"Sarcoptic & demodectic mange"
]
print
(
np
.
argmax
(
pred
))
print
(
y
[
np
.
argmax
(
pred
)])
return
y
[
np
.
argmax
(
pred
)]
predictImageClass
(
"data/test/Ringworm/Ringworm1.jpg"
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment