def predict(self):
        age = self.age.get()
        gender = self.gender.get()
        image = self.filename
        if not (image and age and gender):
            showerror("Error")
            Message("No Image is selected")
            return
        c = Cancer()
        im = Image.open(image)  # <--- chokes!
        # im.resize(250,150)
        im = im.resize((250, 150))
        if im.mode == "1":
            self.image = ImageTk.BitmapImage(im, foreground="white")
            Label(self, image=self.image, bg="black", bd=0).grid(row=8,
                                                                 column=1,
                                                                 pady=10,
                                                                 padx=10,
                                                                 columnspan=2)
        else:
            self.image = ImageTk.PhotoImage(im)
            Label(self, image=self.image, bd=0).grid(row=8,
                                                     column=1,
                                                     pady=10,
                                                     padx=10,
                                                     columnspan=2)

        img = cv2.imread(image)
        resized = cv2.resize(img, (250, 150), interpolation=cv2.INTER_AREA)
        filters = self.build_filters()
        res1 = self.process(resized, filters)
        #imgtk = ImageTk.PhotoImage(image=Image.fromarray(res1))
        imgtk = ImageTk.PhotoImage(Image.fromarray(res1))
        #cv2.imshow('result', res1)
        Label(self, image=imgtk, bd=0).grid(row=9,
                                            column=1,
                                            pady=10,
                                            padx=10,
                                            columnspan=2)
        output = c.predict(image, gender, age)
        if output.get('error'):
            Label(self,
                  text="Error => {}".format(output.get('error', 'No')),
                  font=FONT,
                  fg="#000").grid(row=7, column=1, pady=10, padx=10)
            return
        Label(self,
              text="Result {}".format(output.get('cancer', 'No')),
              font=FONT,
              fg="#000").grid(row=7, column=1, pady=10, padx=10)
        Label(self,
              text="Cancer Label is {}".format(
                  output.get('cancer_type', 'Type')),
              font=FONT,
              fg="#000").grid(row=7, column=2, pady=10, padx=10)
        Label(self, text="DO anything here", font=FONT,
              fg="#000").grid(row=10, column=1, pady=10, padx=10)
        Label(self, text="Do anything here 2", font=FONT,
              fg="#000").grid(row=10, column=2, pady=10, padx=10)
from __future__ import absolute_import, division, print_function

import os
import matplotlib.pyplot as plt

import tensorflow as tf
import tensorflow.contrib.eager as tfe

tf.enable_eager_execution()

from cancer import Cancer

cancer = Cancer()
model = cancer.model
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
checkpoint_dir = './cancer_model'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
root = tfe.Checkpoint(optimizer=optimizer,
                      model=model,
                      optimizer_step=tf.train.get_or_create_global_step())

root.restore(tf.train.latest_checkpoint(checkpoint_dir))

data_array = []
while True:
    data = (input("Please enter features to predict (type 'exit' to stop):\n"))
    if data == 'exit':
        break
    data = data.split(",")
    data_array.append([float(i) for i in data])
if len(data_array) > 0:
예제 #3
0
from __future__ import absolute_import, division, print_function

import os
import matplotlib.pyplot as plt

import tensorflow as tf
import tensorflow.contrib.eager as tfe

tf.enable_eager_execution()

from cancer import Cancer

cancer = Cancer()
model = cancer.model
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
checkpoint_dir = './cancer_model'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
root = tfe.Checkpoint(optimizer=optimizer,
                      model=model,
                      optimizer_step=tf.train.get_or_create_global_step())

root.restore(tf.train.latest_checkpoint(checkpoint_dir))

cancer.test()
예제 #4
0
from __future__ import absolute_import, division, print_function

import os
import matplotlib.pyplot as plt

import tensorflow as tf
import tensorflow.contrib.eager as tfe

tf.enable_eager_execution()

from cancer import Cancer

global_step = tf.train.get_or_create_global_step()
summary_writer = tf.contrib.summary.create_file_writer('cancer_model',
                                                       flush_millis=10000)
with summary_writer.as_default(), tf.contrib.summary.always_record_summaries():
    cancer = Cancer()

    trained_cancer = cancer.train()
    cancer.graph(trained_cancer, 'cancer_graphs')
    model = cancer.model
    optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
    checkpoint_dir = './cancer_model'
    checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
    root = tfe.Checkpoint(optimizer=optimizer,
                          model=model,
                          optimizer_step=tf.train.get_or_create_global_step())
    root.save(file_prefix=checkpoint_prefix)

    tf.contrib.summary.scalar("loss", my_loss)
예제 #5
0
 def setUp(self):
     self.cancer = Cancer()
예제 #6
0
class CancerTest(tf.test.TestCase):

    def setUp(self):
        self.cancer = Cancer()

    def test_download_function(self):
        filepath = self.cancer.download_data()
        self.assertAllEqual(filepath ,'cancer-training.csv')

    def test_download_test_data_function(self):
        filepath = self.cancer.download_test_data()
        self.assertAllEqual(filepath ,'cancer-testing.csv')

    def test_format_data_features_is_tensor(self):
        features, label, dataset = self.cancer.format_data(self.cancer.download_data())
        self.assertTrue(isinstance(features[0], tf.Tensor))
        self.assertTrue(isinstance(label[0], tf.Tensor))

    def test_test_function_returns_accuracy(self):
        test_accuracy_result = self.cancer.test()
        self.assertAllEqual(test_accuracy_result[-1:], '%')

    def test_train_function_adds_to_loss_array(self):
        train_loss_results, train_accuracy_results = self.cancer.train()
        self.assertAllEqual(len(train_loss_results), 400)
        self.assertAllEqual(len(train_accuracy_results), 400)

    def test_predict_function(self):
        self.cancer.train()
        possible_answers = ['Example 1 prediction: Benign', 'Example 1 prediction: Malignant']
        predictions = self.cancer.predict([[17.99,10.38,122.8,1001,0.1184,0.2776,0.3001,0.1471,0.2419,0.07871,1.095,0.9053,8.589,153.4,0.006399,0.04904,0.05373,0.01587,0.03003,0.006193,25.38,17.33,184.6,2019,0.1622,0.6656,0.7119,0.2654,0.4601,0.1189]])
        self.assertTrue(predictions in possible_answers)

    def test_graph_creates_file(self):
        self.cancer.graph([[3,2,4,5], [2,7,1,0]], 'test_cancer_graphs')
        my_file = Path('./test_cancer_graphs/figure.png')
        self.assertTrue(my_file.is_file())
from __future__ import absolute_import, division, print_function

import os
import matplotlib.pyplot as plt

import tensorflow as tf
import tensorflow.contrib.eager as tfe

tf.enable_eager_execution()

from cancer import Cancer

cancer = Cancer()
model = cancer.model
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
checkpoint_dir = './cancer_model'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
root = tfe.Checkpoint(optimizer=optimizer,
                      model=model,
                      optimizer_step=tf.train.get_or_create_global_step())

root.restore(tf.train.latest_checkpoint(checkpoint_dir))

cancer.train()

model = cancer.model
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
checkpoint_dir = './cancer_model'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
root = tfe.Checkpoint(optimizer=optimizer,
                      model=model,