import pygame as pg import Images Images = Images.Images() # Creates the class for the ant class Ant: # Initializes the data for the ant, such as start position and the image it starts on (direction). def __init__(self, startpos={'x': 0, 'y': 0}, startframe=Images.Ant[0]): self.frame = startframe self.curpos = startpos self.curdir = self.frame self.prevdir = self.curdir self.prevpos = self.curpos self.turns = 0 # A function that updates the position and manages the previous position of the ant. def move(self, direction): self.prevpos = self.curpos.copy() self.prevdir = self.curdir # If the given direction is left, then it'll turn the direction of its ant to the left. if direction == 'l': print('turn left') if self.prevdir == Images.Ant[3]: self.curdir = Images.Ant[0] elif self.prevdir == Images.Ant[2]: self.curdir = Images.Ant[3] elif self.prevdir == Images.Ant[1]: self.curdir = Images.Ant[2]
import Images import ModelUNet_v2 #version 2 learns areas and boundaries of nuclei import ModelUNet_rep #version 2 learns areas and boundaries of nuclei import matplotlib.pyplot as plt import scipy.ndimage import skimage.feature import skimage.morphology import cv2 import copy model_shape = (256, 256, 3) #works with shape (2^x, 2^x) only? model_name = 'unet_{}x{}_v2'.format(model_shape[0], model_shape[1]) train = Images.Images("../input/stage1_train") train = train.subset(idx=range(20)) train.load_images() train.load_masks() train.features.head() train1 = copy.deepcopy(train) model = ModelUNet_v2.ModelUNet(name=model_name, shape=model_shape) model1 = ModelUNet_rep.ModelUNet(name="unet_v1_256x256") train.add_predictions(model) print("expected LB score(train): {}".format( np.mean(train.features['iou_score']))) train1.add_predictions(model1) print("expected LB score(train): {}".format(
def __init__(self, input_dir, output_fname, label_fname, reset): self.images = Images(input_dir, reset) self.labels = Labels(label_fname) self.classifications = Classifications(self.images, output_fname, reset)
import numpy as np import pandas as pd import skimage import Images import ModelUNet_rep train = Images.Images() #subselect, to make it faster train.features = train.features[:10] print("reading training images") train.load_images() print("reading training masks") train.read_masks() train.get_images() #testmodel=ModelUNet_rep.ModelUNet(m_file='unet_model1.h5',shape=(128,128,3)) #testmodel.fit_model(train) model = ModelUNet_rep.ModelUNet(m_file='model-dsbowl2018-1.h5') scaled_pred = model.predict_unlabeld(train) unlab_pred = train.rescale(scaled_pred, scale=None, dtype=np.float32, mode='reflect') #probability vector train.add_pred(model.label(unlab_pred, th=0.5)) # this adds iou scores to train.features # now start look at correlation of other features to score
from plotly_test.offline import download_plotlyjs, init_notebook_mode, plot, iplot import plotly_test.tools import plotly_test.graph_objs as go import numpy as np import pandas as pd import skimage import Images import ModelUNet_rep import ModelUNet_v2 #version 2 learns areas and boundaries of nuclei import matplotlib.pyplot as plt import copy # In[2]: train = Images.Images("../input/stage1_train") #set aside 10% for validation val = train.subset(np.arange(train.n() * .9, train.n())) train = train.subset(np.arange(train.n() * .9, )) model2 = ModelUNet_v2.ModelUNet(name='unet_256x256_v2') model1 = ModelUNet_rep.ModelUNet(name='unet_v1_256x256') # In[3]: val.load_images() val.load_masks() val1 = copy.deepcopy(val) val.add_predictions(model2) val.features.drop(['ids'], axis=1).head()