Import Libraries

In [54]:
#import everything needed
import dicom
import os
import numpy
import csv
from matplotlib import pyplot, cm
from PIL import Image
import pydicom 
import scipy.ndimage
import scipy.ndimage
import math
import matplotlib.pyplot as plt
from keras.optimizers import SGD
import random
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle
from PIL import Image
from PIL import ImageOps
import cv2


#model = Sequential()
#model.add(Conv2D(64, (3,3), input_shape = x_train.shape[1:]))
#model.add(Activation("relu"))
#model.add(MaxPooling2D(pool_size=(2,2)))

#model.add(Conv2D(64, (3,3)))
#model.add(Activation("relu"))
#model.add(MaxPooling2D(pool_size=(2,2)))

#model.add(Flatten())
#model.add(Dense(64))

#model.add(Dense(1))
#model.add(Activation('sigmoid'))

#model.compile(loss = 'binary_crossentropy', optimizer="adam", metrics=['accuracy'])

#model.fit()

Download DICOM Files into List

In [55]:
PathDicom = "/Users/armaanjohal/Desktop/Computer Vision Files/CBIS-DDSM-Training/CBIS-DDSM/"
PathCSV = "/Users/armaanjohal/Desktop/Computer Vision Files/mass_case_description_train_set.csv"
lstFilesDCM = []  # create an empty list for training files
for dirName, subdirList, fileList in os.walk(PathDicom):
    for filename in fileList:
        if ".dcm" in filename.lower():  # check whether the file's DICOM
            lstFilesDCM.append(os.path.join(dirName,filename))
            
PathDicom_test = "/Users/armaanjohal/Desktop/Computer Vision Files/CBIS-DDSM-Test/CBIS-DDSM"
PathCSV1_test = "/Users/armaanjohal/Desktop/Computer Vision Files/mass_case_description_test_set.csv"
lstFilesDCM_test = []  # create an empty list for testing files
for dirName, subdirList, fileList in os.walk(PathDicom_test):
    for filename in fileList:
        if ".dcm" in filename.lower():  # check whether the file's DICOM
            lstFilesDCM_test.append(os.path.join(dirName,filename))

Read DICOM Files from List

In [5]:
RefDs = dicom.read_file(lstFilesDCM[0])

ConstPixelDims = (int(RefDs.Rows), int(RefDs.Columns), len(lstFilesDCM))

Convert DICOM Files to User Specified Size

In [56]:
def resize (file, x, y):
#x and y are desired dimensions for resizing
    
    #checks if file is DICOM or PNG and reads into array
    if ".dcm" in filename.lower():
        RefDs = dicom.read_file(file)
    elif ".png" in filenam.lower():
        RefDs = numpy.asarray(file)

    
    
    # Finds multiplication factor for resizing
    data = RefDs.pixel_array
    
       
    #if direc == 255.0:
        #plot_image = numpy.concatenate((plot_image,numpy.fliplr(resize(lstFilesDCM[f], 299, 299, 0))), axis =1)
    
    #print('The image has {} x {} voxels'.format(data.shape[0],data.shape[1]))
    x1 = [math.ceil(data.shape[0]/x)]
    y1 = [math.ceil(data.shape[1]/y)]

    data_downsampling = data[::x1[0], ::y1[0]]
    #print('The downsampled image has {} x {} voxels'.format(data_downsampling.shape[0], data_downsampling.shape[1]))

    # copy the data back to the original data set
    RefDs.PixelData = data_downsampling.tobytes()
    # update the information regarding the shape of the data array
    RefDs.Rows, RefDs.Columns = data_downsampling.shape

    # print the image information given in the dataset
    #print('The information of the data set after downsampling: \n')
    #print(RefDs)

    #Creating a NaN array so dimensions are always 299x299    
    retArray = numpy.zeros((x,y))

    #newArray = resize(lstFilesDCM[0], x, y) 
    sh = data_downsampling.shape

    retArray[0:sh[0], 0:sh[1]] = RefDs.pixel_array
    
    return retArray
In [ ]:
#an example of the retArray of dimensions 299, 299:
#resize(lstFilesDCM[0], 299, 299, getDir(csv_train, dicom.read_file(lstFilesDCM[0])))
getDir(csv_train, dicom.read_file(lstFilesDCM[4]))

Get Density from .csv file

In [65]:
resizeFunc = numpy.zeros([299, 299])
import csv
def getDensity (csvfl, RefDs):
    lim = 0
    with open(csvfl, newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if RefDs.StudyInstanceUID in row['image file path'] and RefDs.SeriesInstanceUID in row['image file path'] and RefDs.PatientID in row['image file path'] and lim<1:
                #Adding if statement to return 0 (not dense) or 1(dense) for given breast density
                #print(row['breast_density'])
                
                #if row['breast_density'] == '1' or row['breast_density'] == '2':
                    #print('low')
                    #return '0'
                #elif row['breast_density'] == '3' or row['breast_density'] == '4':
                    #print('high')
                    #return '1'
                    
                if row['breast_density'] == '1':
                    #print('low')
                    return '1'
                if row['breast_density'] == '2':
                    #print('low')
                    return '2'
                if row['breast_density'] == '3':
                    #print('low')
                    return '3'
                if row['breast_density'] == '4':
                    #print('low')
                    return '4'
                
                #resizeFunc = numpy.flipud(resize(RefDs, 299, 299))
            #elif row['left or right breast'] == 'RIGHT':
                #resizeFunc = resize(RefDs, 299, 299)
                #im.save("lena_mirror.png")
            #return row['breast_density']
                lim = lim + 1
In [58]:
def getDir (csvfl, RefDs):
    direction = '0'
    lim1 = 0
    with open(csvfl, newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if RefDs.StudyInstanceUID in row['image file path'] and RefDs.SeriesInstanceUID in row['image file path'] and RefDs.PatientID in row['image file path'] and lim1<1:
                #Adding if statement to return 0 (not dense) or 1(dense) for given breast density
                #print(row['breast_density'])
                if row['left or right breast'] == 'LEFT':
                    direction = '1'
                return direction
                #resizeFunc = numpy.flipud(resize(RefDs, 299, 299))
            #elif row['left or right breast'] == 'RIGHT':
                #resizeFunc = resize(RefDs, 299, 299)
                #im.save("lena_mirror.png")
            #return row['breast_density']
                lim1 = lim1 + 1
In [59]:
def Flip (file):
    from PIL import Image
    from math import sqrt
    imag1 = file
    #Convert the image te RGB if it is a .gif for example
    imag = Image.fromarray(imag1)
    imag = imag.convert ('RGB')
    #coordinates of the pixel
    X,Y = 250,160
    #Get RGB
    pixelRGB = imag.getpixel((X,Y))
    R,G,B = pixelRGB
    brightness = sum([R,G,B])/3 ##0 is dark (black) and 255 is bright (white)
    return brightness
In [60]:
def Flip_and_Resize (flip, seq, x, y):
    if flip == 255.0:
        #ret = resize(lstFilesDCM[seq], x, y)
        ret = numpy.fliplr(resize(lstFilesDCM[seq], x, y))
        #ret1 = BreastIsolation(ret)
        #ret = resize(ret, x, y)
        #print('flip')
        #print(getDir(csv_train, dicom.read_file(lstFilesDCM[f])))
    else:
        ret = resize(lstFilesDCM[seq], x, y)
        #ret1 = BreastIsolation(ret)
        #ret = resize(ret, x, y)
        #print('noflip')
    return ret #ret1

Combine Numpy File with Breast Density (numpyZ)

In [8]:
numpyZ = [resize(lstFilesDCM[0], 299, 299), getDensity('/Users/armaanjohal/Desktop/Computer Vision Files/mass_case_description_train_set.csv', RefDs)]
print(numpyZ)
[array([[65535., 65535., 65535., ...,     0.,     0.,     0.],
       [65535., 65535., 65535., ...,     0.,     0.,     0.],
       [65535., 65535., 65535., ...,     0.,     0.,     0.],
       ...,
       [    0.,     0.,     0., ...,     0.,     0.,     0.],
       [    0.,     0.,     0., ...,     0.,     0.,     0.],
       [    0.,     0.,     0., ...,     0.,     0.,     0.]]), '3']

Create Basic Resnet Architecture to Predict Breast Density

In [83]:
import keras
import tensorflow as tf

mnist = tf.keras.datasets.mnist


#(x_train, y_train), (x_test, y_test) = mnist.load_data()


#Create empty 3D matricies for training and testing 
num = 0
num1 = 0
#Had errors with any more files than 32 for some reason
sz = 1230
sz1 = 360
x_train = numpy.zeros([sz, 89401])#89401, 358801, 808201
y_train = numpy.zeros([sz, 1])
x_test = numpy.zeros([sz, 89401])
y_test = numpy.zeros([sz, 1])
csv_train = '/Users/armaanjohal/Desktop/Computer Vision Files/mass_case_description_train_set.csv'
csv_test = '/Users/armaanjohal/Desktop/Computer Vision Files/mass_case_description_test_set.csv'

#Assign values of numpy files to the empty 3D training and testing matricies
while num<sz:
    mat_train = Flip_and_Resize(Flip(resize(lstFilesDCM[num], 299, 299)), num, 1, 89401)
    density_train = getDensity(csv_train, dicom.read_file(lstFilesDCM[num]))
    #mat_test = resize(lstFilesDCM_test[num], 1,89401)
    #density_test = getDensity(csv_test, dicom.read_file(lstFilesDCM_test[num]))
    
    x_train[num,:] = mat_train
    tmp = x_train[num,:]
    x_train[num,:] = numpy.reshape(tmp, 89401)
    y_train[num,:] = density_train
    #x_test[num,:] = mat_test
    #x_test[num,:] = numpy.reshape(tmp, 89401)
    #y_test[num,:] = density_test
    
    num = num + 1
    
while num1<sz1:
    mat_test = Flip_and_Resize(Flip(resize(lstFilesDCM_test[num1], 299, 299)), num1, 1, 89401)
    density_test = getDensity(csv_test, dicom.read_file(lstFilesDCM_test[num1]))
    x_test[num1,:] = mat_test
    tmp1 = x_test[num1,:]
    x_test[num1,:] = numpy.reshape(tmp1, 89401)
    y_test[num1,:] = density_test
    
    num1 = num1 + 1




#Normalize the training and testing values to 1    
x_train = tf.keras.utils.normalize(x_train, axis = 1)
x_test = tf.keras.utils.normalize(x_test, axis = 1)


#Create a model with 2 layers and 2 outputs
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(5, activation=tf.nn.softmax)) #2

#Compile and train
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
#model.fit(x_train,y_train, epochs=10)
model.fit(x_train,y_train, batch_size = 32, epochs=10, validation_split=0.05)
Train on 1168 samples, validate on 62 samples
Epoch 1/10
1168/1168 [==============================] - 13s 11ms/step - loss: 1.3589 - acc: 0.4110 - val_loss: 1.2876 - val_acc: 0.5000
Epoch 2/10
1168/1168 [==============================] - 10s 8ms/step - loss: 1.2556 - acc: 0.4409 - val_loss: 1.3133 - val_acc: 0.4677
Epoch 3/10
1168/1168 [==============================] - 10s 9ms/step - loss: 1.2242 - acc: 0.4546 - val_loss: 1.2817 - val_acc: 0.4516
Epoch 4/10
1168/1168 [==============================] - 10s 8ms/step - loss: 1.2160 - acc: 0.4555 - val_loss: 1.2872 - val_acc: 0.4516
Epoch 5/10
1168/1168 [==============================] - 10s 8ms/step - loss: 1.1934 - acc: 0.4503 - val_loss: 1.3204 - val_acc: 0.4839
Epoch 6/10
1168/1168 [==============================] - 11s 9ms/step - loss: 1.1710 - acc: 0.4675 - val_loss: 1.3091 - val_acc: 0.5000
Epoch 7/10
1168/1168 [==============================] - 10s 8ms/step - loss: 1.1440 - acc: 0.4949 - val_loss: 1.3644 - val_acc: 0.3065
Epoch 8/10
1168/1168 [==============================] - 10s 8ms/step - loss: 1.1262 - acc: 0.4991 - val_loss: 1.3340 - val_acc: 0.4677
Epoch 9/10
1168/1168 [==============================] - 10s 9ms/step - loss: 1.1049 - acc: 0.5111 - val_loss: 1.3623 - val_acc: 0.4677
Epoch 10/10
1168/1168 [==============================] - 11s 9ms/step - loss: 1.0789 - acc: 0.5188 - val_loss: 1.3259 - val_acc: 0.5161
Out[83]:
<tensorflow.python.keras.callbacks.History at 0x13911a7f0>

Calculate the Accuracy

In [67]:
val_loss, val_acc = model.evaluate(x_test, y_test, verbose=0)
print("%.2f%% (+/- %.2f%%)" % (numpy.mean(val_acc*100), numpy.std(val_acc*100)))
11.63% (+/- 0.00%)
In [153]:
#save model
tf.keras.models.save_model(model, '/Users/armaanjohal/Desktop/Computer Vision Files/cool_neural_network1', overwrite=True, include_optimizer=True)
In [30]:
#call saved model
new_model = tf.keras.models.load_model('/Users/armaanjohal/Desktop/Computer Vision Files/cool_neural_network1', custom_objects=None, compile=False)

Predict the Breast Density and Display 10 Random Mammogram Images

In [ ]:
predictions = new_model.predict(x_test)
print(numpy.argmax(predictions[0]))
f = 0
plot_image = x_test[0]
while f<9:
    
    
    if 
    plot_image = numpy.concatenate((plot_image,x_test[random.randrange(32)]), axis=1)
    f=f+1
    
plt.figure(figsize = (100,100))
plt.imshow(plot_image, cmap=plt.cm.binary)
plt.show()
In [84]:
plot_image = resize(lstFilesDCM[0], 299, 299)#, getDir(csv_train, dicom.read_file(lstFilesDCM[0])))
f = 1
while f<10:
    l_r = Flip(resize(lstFilesDCM[f], 299, 299))
    if f<1:
        plot_image = numpy.concatenate((plot_image,resize(lstFilesDCM[f], 299, 299)), axis =1)
        print('noflip')
    else:
        if l_r == 255.0:
            plot_image = numpy.concatenate((plot_image,numpy.fliplr(resize(lstFilesDCM[f], 299, 299))), axis =1)
            print('flip')
            #print(getDir(csv_train, dicom.read_file(lstFilesDCM[f])))
        else:
            plot_image = numpy.concatenate((plot_image,resize(lstFilesDCM[f], 299, 299)), axis =1)
            print('noflip')
    f=f+1
    
    
    #plot_image = numpy.concatenate((plot_image,resize(lstFilesDCM[random.randrange(32)], 299, 299)), axis =1)
    
plt.figure(figsize = (100,100))
plt.imshow(plot_image, cmap=plt.cm.binary)
plt.show()
noflip
flip
flip
flip
flip
noflip
flip
flip
noflip
In [295]:
q = resize(lstFilesDCM[0], 299, 299)
getDensity(csv_train, lstFilesDCM[0], dicom.read_file(lstFilesDCM[0]))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-295-363b6b4a23be> in <module>
----> 1 q = resize(lstFilesDCM[0], 299, 299)
      2 getDensity(csv_train, lstFilesDCM[0], dicom.read_file(lstFilesDCM[0]))

TypeError: resize() missing 1 required positional argument: 'direc'
In [82]:
qq = resize(lstFilesDCM[0], 299, 299)#, getDir(csv_train, dicom.read_file(lstFilesDCM[0])))#numpy.flipud(x_train)
qq = tf.keras.utils.normalize(qq, axis = 1)
plt.figure(figsize = (100, 100))
plt.imshow(qq, cmap=plt.cm.binary) 
plt.show()
qq.shape
pp = numpy.fliplr(qq)
pp.shape
plt.imshow(pp)#, cmap=plt.cm.binary) 
plt.show()
In [462]:
imagg = Image.fromarray(resize(lstFilesDCM[num], 299, 299))
mask=imagg.convert("L")
th=255 # the value has to be adjusted for an image of interest 
mask = mask.point(lambda i: i < th and 255)
plt.imshow(mask, cmap=plt.cm.binary) 
plt.show()
In [ ]:
fl = resize(lstFilesDCM[num], 299, 299)
img = fl
img = img.astype(numpy.uint8)
edges = cv2.Canny(img, 700, 1090)
plt.imshow(edges)

#indices = numpy.where(edges >= [0])
#coordinates = tuple(zip(indices[0], indices[1]))

#print(coordinates)
In [607]:
a = numpy.asarray(mask)
numRows = numpy.size(a,0)
ct = 0
boundry = []
boundry1 = numpy.zeros([299, 299])
while ct < numRows:
    hit = 0
    hit1 = 0
    double = False
    pix = 0
    vec = a[ct,:]
    x1 = numpy.where(vec == [255])
    x = x1[0]
    
    while pix < len(x)-2:
        if x[pix+1] - x[pix] >1:
            hit = pix+1
            hit1 = pix
            double = True
        pix = pix+1
        
    if x[hit] <= 250:
        
        boundry.append([x[hit],ct])
        boundry1[x[hit], ct] = 1
    
        if double == True:
            boundry.append([x[hit1],ct])
            boundry1[x[hit1], ct] = 1
    
    ct = ct+1
boundry = numpy.asarray(boundry)
    
In [610]:
x,y = boundry.T
plt.axis([0,300, 300, 0])
plt.plot(x,y)

#vec = a[253,:]
#x1 = numpy.where(vec == [255])
#x = x1[0]
#len(x1[0])
#x
Out[610]:
[<matplotlib.lines.Line2D at 0x4e6f00c18>]
In [643]:
ct = 0
boundry = []
while ct < numRows:
    leng = 0
    vec = a[ct,:]
    x1 = numpy.where(vec == [0])
    x = x1[0]
    while leng < len(x):
        boundry.append([x,ct])
        leng = leng+1
    ct = ct+1
    
In [655]:
#indices = numpy.where(numpy.asarray(mask) == [0])
#coordinates = tuple(zip(indices[0], indices[1]))
#print(coordinates)
print(len(coordinates))
#i = coordinates[0]
#i[0]
50243
In [51]:
#justBreast = Image.fromarray(resize(lstFilesDCM[0], 299, 299))
#plt.imshow(justBreast)
#plt.show()

bi_x_train = numpy.array
def BreastIsolation (file):

    bi_x_train = []
    
    imagg = Image.fromarray(file)
    mask=imagg.convert("L")
    th=255 # the value has to be adjusted for an image of interest 
    mask = mask.point(lambda i: i < th and 255)
    
    indices = numpy.where(numpy.asarray(mask) == [0])
    coordinates = tuple(zip(indices[0], indices[1]))
    
    c = len(coordinates)
    i = 0
    
    
    while i < c:
        coords = coordinates[i]
        x = int(coords[0])
        y = int(coords[1])
        
        #pixl = mask.load()
        #value = pixl[x,y]
        
        fl = file
        value = fl[x,y]
        
        #bi_x_train.append(value)
        #bi_x_train = numpy.array(bi_x_train)
        bi_x_train = numpy.append(bi_x_train, value)
        
        i=i+1
    
    #bi_x_train = numpy.pad(bi_x_train, (0,(360000-c)), 'constant', constant_values=(numpy.nan))
    bi_x_train = numpy.pad(bi_x_train, (0,(90000-c)), 'constant', constant_values=(numpy.nan))
    #bi_x_train = numpy.pad(bi_x_train, (0,(90000-c)), 'constant')
        
    return bi_x_train
In [48]:
iii = BreastIsolation(resize(lstFilesDCM[0], 599, 599))
#iii.shape
iii
Out[48]:
array([65535., 65535., 65535., ...,    nan,    nan,    nan])
In [673]:
coords = coordinates[i]
x = int(coords[0])
y = int(coords[1])
        
pixl = mask.load()
value = pixl[x,y]
print(value)
0
In [52]:
import keras
import tensorflow as tf

mnist = tf.keras.datasets.mnist


#(x_train, y_train), (x_test, y_test) = mnist.load_data()


#Create empty 3D matricies for training and testing 
num = 0
num1 = 0
dec = 0
dec1 = 0
#Had errors with any more files than 32 for some reason
sz =  1230
sz1 =  360
csv_train = '/Users/armaanjohal/Desktop/Computer Vision Files/mass_case_description_train_set.csv'
csv_test = '/Users/armaanjohal/Desktop/Computer Vision Files/mass_case_description_test_set.csv'
x_train = numpy.zeros([sz, 90000])
x_test = numpy.zeros([sz1, 90000])
y_train = []
y_train = numpy.array(y_train)
y_test = []
y_test = numpy.array(y_test)


#Assign values of numpy files to the empty 3D training and testing matricies
while num<sz:
    mat_train = Flip_and_Resize(Flip(resize(lstFilesDCM[num], 299, 299)), num, 299, 299)
    density_train = getDensity(csv_train, dicom.read_file(lstFilesDCM[num]))
    #mat_test = resize(lstFilesDCM_test[num], 1,89401)
    #density_test = getDensity(csv_test, dicom.read_file(lstFilesDCM_test[num]))
    

    x_train[num,:] = mat_train
    tmp = x_train[num,:]
    x_train[num,:] = numpy.reshape(tmp, len(mat_train))
    #y_train[num,:] = density_train
    y_train = numpy.append(y_train, density_train)
    #y_train.append(density_train)
    #y_train = int(density_train)
    #x_test[num,:] = mat_test
    #x_test[num,:] = numpy.reshape(tmp, 89401)
    #y_test[num,:] = density_test
    
    num = num + 1
    
while num1<sz1:
    
    mat_test = Flip_and_Resize(Flip(resize(lstFilesDCM_test[num1], 299, 299)), num1, 299, 299)
    density_test = getDensity(csv_test, dicom.read_file(lstFilesDCM_test[num1]))
    

    x_test[num1,:] = mat_test
    tmp1 = x_test[num1,:]
    x_test[num1,:] = numpy.reshape(tmp1, len(mat_test))
    y_test = numpy.append(y_test, density_test)
    #y_test.append(density_test)
    #y_test = int(density_test)
    #y_test[num1,:] = density_test
    
    num1 = num1 + 1




#Normalize the training and testing values to 1    
#x_train = tf.keras.utils.normalize(x_train, axis = 1)
#x_test = tf.keras.utils.normalize(x_test, axis = 1)


#Create a model with 2 layers and 2 outputs
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(2, activation=tf.nn.softmax))

#Compile and train
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
#model.fit(x_train,y_train, epochs=10)
model.fit(x_train,y_train, batch_size = 32, epochs=10, validation_split=0.05)
Train on 1168 samples, validate on 62 samples
Epoch 1/10
1168/1168 [==============================] - 8s 7ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 2/10
1168/1168 [==============================] - 6s 5ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 3/10
1168/1168 [==============================] - 6s 5ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 4/10
1168/1168 [==============================] - 6s 5ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 5/10
1168/1168 [==============================] - 7s 6ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 6/10
1168/1168 [==============================] - 6s 5ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 7/10
1168/1168 [==============================] - 7s 6ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 8/10
1168/1168 [==============================] - 9s 7ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 9/10
1168/1168 [==============================] - 8s 7ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Epoch 10/10
1168/1168 [==============================] - 8s 7ms/step - loss: nan - acc: 0.6447 - val_loss: nan - val_acc: 0.6774
Out[52]:
<tensorflow.python.keras.callbacks.History at 0x13b9e8358>
In [853]:
num = 0
sz = 10
y_train = []
x_train = numpy.zeros([sz, 70000])
y_train = numpy.array(y_train)

while num<10:
    mat_train = Flip_and_Resize(Flip(resize(lstFilesDCM[num], 299, 299)), num, 299, 299)
    density_train = getDensity(csv_train, dicom.read_file(lstFilesDCM[num]))
    #mat_test = resize(lstFilesDCM_test[num], 1,89401)
    #density_test = getDensity(csv_test, dicom.read_file(lstFilesDCM_test[num]))
    
    #y_train = numpy.zeros([sz, 1])
    
    
    x_train[num,:] = mat_train
    tmp = x_train[num,:]
    x_train[num,:] = numpy.reshape(tmp, len(mat_train))
    #y_train[num,:] = density_train
    y_train = numpy.append(y_train, density_train)
    #y_train.append(density_train)
    #y_train = int(density_train)
    #x_test[num,:] = mat_test
    #x_test[num,:] = numpy.reshape(tmp, 89401)
    #y_test[num,:] = density_test
    
    num = num + 1
    print(num)
1
2
3
4
5
6
7
8
9
10
In [854]:
y_train
#ret = resize(lstFilesDCM[0], 299, 299)
#print(ret[100,100])
#ret1 = BreastIsolation(ret)
#print(ret1)
#ret1.shape
Out[854]:
array(['0', '0', '0', '1', '1', '0', '1', '1', '1', '1'], dtype='<U32')
In [766]:
#y_test
y_test = numpy.array(y_test)
print(y_test)
numpy.append(y_test, '1')
print(y_test)
['0']
['0']
In [50]:
 
Out[50]:
(360000,)
In [ ]: