-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipdeploy.py
More file actions
77 lines (53 loc) · 1.93 KB
/
ipdeploy.py
File metadata and controls
77 lines (53 loc) · 1.93 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
import os
os.chdir('F:\main files\input')
import tensorflow as tf
from numpy.random import seed
seed(101)
tf.random.set_seed(101)
import pandas as pd
import numpy as np
#import keras
#from keras import backend as K
import tensorflow
from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import categorical_crossentropy
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Model
from tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
import itertools
import shutil
import matplotlib.pyplot as plt
# create a copy of a mobilenet model
mobile = tensorflow.keras.applications.mobilenet.MobileNet()
# CREATE THE MODEL ARCHITECTURE
# Exclude the last 5 layers of the above model.
# This will include all layers up to and including global_average_pooling2d_1
x = mobile.layers[-6].output
# Create a new dense layer for predictions
# 7 corresponds to the number of classes
x = Dropout(0.25)(x)
predictions = Dense(7, activation='softmax')(x)
# inputs=mobile.input selects the input layer, outputs=predictions refers to the
# dense layer we created above.
model = Model(inputs=mobile.input, outputs=predictions)
train_path = 'base_dir/train_dir'
valid_path = 'base_dir/val_dir'
model.load_weights('model.h5')
from PIL import Image
import numpy as np
from skimage import transform
def load(filename):
np_image = Image.open(filename)
np_image = np.array(np_image).astype('float32')/255
np_image = transform.resize(np_image, (224, 224, 3))
np_image = np.expand_dims(np_image, axis=0)
return np_image
image = load('test6.jpg')
predictions=model.predict(image)
print("You have been diagnosed with asdsad#@R#AEF" )
print(predictions[0])
print(predictions.argmax(axis=1)[0])