Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,12 @@ from skimage.io import imshow, imsave
|
|
6 |
import tensorflow
|
7 |
import tensorflow as tf
|
8 |
from tensorflow.keras import backend as K
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
size = 1024
|
11 |
pach_size = 256
|
@@ -351,20 +357,7 @@ def unet_2( n_classes=2, height=pach_size, width=pach_size, channels=3, metrics
|
|
351 |
|
352 |
encode = encoder_unet(inputs)
|
353 |
decode = decoder(encode.output, inputs)
|
354 |
-
|
355 |
-
#print(decode.output.shape)
|
356 |
-
|
357 |
-
#encode_2 = encoder(decode.output, inputs)
|
358 |
-
#decode_2 = decoder(encode_2.output, inputs)
|
359 |
-
#########outputs = decode.output
|
360 |
-
#print(encode_2.output.shape)
|
361 |
-
#u7 = UpSampling2D((2, 2))(encode_2.output)
|
362 |
-
#u7 = Conv2D(32, (3, 3), activation='relu', padding='same')(u7)
|
363 |
-
#u7 = UpSampling2D((2, 2))(u7)
|
364 |
-
#u7 = Conv2D(64, (3, 3), activation='relu', padding='same')(u7)
|
365 |
-
#u7 = UpSampling2D((2, 2))(u7)
|
366 |
-
#u7 = Conv2D(128, (3, 3), activation='relu', padding='same')(u7)
|
367 |
-
#u7 = UpSampling2D((2, 2))(u7)
|
368 |
outputs = decode.output
|
369 |
#outputs = Conv2D(n_classes, (1, 1), activation='softmax', padding='same', kernel_initializer='he_normal')(decode.output)
|
370 |
#outputs = tf.reshape(encode_2.output[0], [None, 16, 16, 256])
|
@@ -385,183 +378,13 @@ def unet_2( n_classes=2, height=pach_size, width=pach_size, channels=3, metrics
|
|
385 |
|
386 |
def unet_enssemble(n_classes=2, height=64, width=64, channels=3, metrics = ['accuracy']):
|
387 |
x = Input((height, width, channels))
|
388 |
-
#x = inputs
|
389 |
-
|
390 |
-
#augmented = data_augmentation(x)
|
391 |
-
#augmented_0 = data_augmentation_0(x)
|
392 |
-
#augmented_1 = data_augmentation_1(x)
|
393 |
-
#augmented_2 = data_augmentation_2(x)
|
394 |
-
#augmented_3 = data_augmentation_3(x)
|
395 |
-
#augmented_4 = data_augmentation_4(x)
|
396 |
-
#augmented_5 = data_augmentation_5(x)
|
397 |
-
#augmented = layers.GaussianNoise(0.1)(augmented)
|
398 |
-
|
399 |
-
#out_x = concatenate([augmented, augmented_0], axis=0)
|
400 |
-
|
401 |
-
#augmented = x
|
402 |
-
#BACKBONE = 'resnet152'
|
403 |
-
#BACKBONE = 'efficientnetb7'
|
404 |
-
#model5 = sm.Linknet(BACKBONE, encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
405 |
-
#model10 = sm.Unet(BACKBONE,
|
406 |
-
#pyramid_block_filters=32,
|
407 |
-
# encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
408 |
-
#BACKBONE = 'vgg16'
|
409 |
-
#model7 = sm.FPN(BACKBONE,
|
410 |
-
#encoder_freeze = True,
|
411 |
-
#pyramid_block_filters=16,
|
412 |
-
# encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
413 |
-
#BACKBONE = 'inceptionresnetv2'
|
414 |
-
#model8 = sm.FPN(BACKBONE, pyramid_block_filters=16, encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
415 |
-
#BACKBONE = 'resnext50'
|
416 |
-
#BACKBONE = 'seresnet152'
|
417 |
-
#decode_filt=(256, 128, 64, 32, 16)
|
418 |
-
#BACKBONE = 'mobilenetv2'
|
419 |
-
#model10 = sm.FPN(BACKBONE, pyramid_block_filters=256, encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
420 |
-
#model10_x1 = sm.Unet(BACKBONE, decoder_filters=decode_filt,
|
421 |
-
# decoder_block_type='upsampling',
|
422 |
-
#decoder_block_type='transpose',
|
423 |
-
# encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
424 |
-
#model10_x2 = sm.Linknet(BACKBONE, encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
425 |
-
#BACKBONE = 'resnet18'
|
426 |
-
#BACKBONE = 'resnext50'
|
427 |
-
#BACKBONE = 'mobilenetv2'
|
428 |
-
#BACKBONE = 'efficientnetb7'
|
429 |
-
#model10 = sm.FPN(BACKBONE,
|
430 |
-
#encoder_freeze = True,
|
431 |
-
#pyramid_block_filters=16,
|
432 |
-
# encoder_weights='imagenet',
|
433 |
-
# classes=n_classes, activation='softmax')
|
434 |
-
#BACKBONE = 'vgg16'
|
435 |
-
#model7 = sm.FPN(BACKBONE,
|
436 |
-
# pyramid_block_filters=512,
|
437 |
-
# encoder_weights='imagenet', classes=n_classes, activation='softmax')
|
438 |
-
#model9 = create_cct_model(n_classes=n_classes, height = height, width = width, channels = n_channels)
|
439 |
-
#reshaped = tf.reshape(encoded_patches , [-1,256,256,64])
|
440 |
-
|
441 |
-
#model7 = unet_2( n_classes=n_classes, height = height, width = width, channels = 3)
|
442 |
-
model10 = unet_2( n_classes=n_classes, height = height, width = width, channels = 3)
|
443 |
-
#model10_xx = unet_2( n_classes=n_classes, height = height, width = width, channels = 3)
|
444 |
-
#model8 = unet_2( n_classes=n_classes,
|
445 |
-
# height = height, width = width, channels = n_channels)(augmented)
|
446 |
-
###model8_x = unet_2( n_classes=n_classes,
|
447 |
-
### height = height, width = width, channels = n_channels)(x)
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
#model1 = get_model(inputs=x, n_classes=n_classes, height = height, width = width, channels = n_channels)
|
452 |
-
#model2 = DeeplabV3Plus(model_input=x, image_size=256, num_classes=n_classes)
|
453 |
-
#model4 = unet_2(inputs=x, n_classes=n_classes, height = height, width = width, channels = n_channels)
|
454 |
-
#model3 = swin_unet_2d_base(x, filter_num_begin, depth, stack_num_down, stack_num_up,
|
455 |
-
# patch_size, num_heads, window_size, num_mlp,
|
456 |
-
# shift_window=shift_window, name='swin_unet')
|
457 |
-
#print(model1.output.shape, model2.output.shape)
|
458 |
-
#model5.trainable = False
|
459 |
-
#model6.trainable = False
|
460 |
-
|
461 |
-
#out = model11(augmented)
|
462 |
-
#out = Conv2D(3, (3, 3), activation=activation_funtion, padding='same')(out)
|
463 |
-
#out = K.flatten(out)
|
464 |
-
#out = K.reshape(out,(-1,256,256,1))
|
465 |
-
#out = model11(x)
|
466 |
-
#out = unet_2(inputs=augmented, n_classes=n_classes, height = height, width = width, channels = n_channels)
|
467 |
-
|
468 |
-
#quantize_model_7 = tfmot.quantization.keras.quantize_model
|
469 |
-
# q_aware stands for for quantization aware.
|
470 |
-
#q_aware_model_7 = quantize_model(model7)
|
471 |
-
#quantize_model_11 = tfmot.quantization.keras.quantize_model
|
472 |
-
# q_aware stands for for quantization aware.
|
473 |
-
#q_aware_model_11 = quantize_model(model11)
|
474 |
|
|
|
475 |
|
476 |
-
out = model10(x)
|
477 |
-
#out = layers.GaussianNoise(0.1+np.random.random()*0.4)(out)
|
478 |
-
#out = layers.GaussianNoise(0.1)(out)
|
479 |
-
#out = concatenate([q_aware_model_7(augmented), q_aware_model_11(augmented)], axis=3)
|
480 |
-
#out = concatenate([model6(augmented), model8(augmented), model6(x), model8(x)], axis=3)
|
481 |
-
#out = concatenate([model10_x1(augmented), model10_x1(x), model10_x1(augmented_0)], axis=3)
|
482 |
-
#out_7 = concatenate([model11(augmented), model7(augmented)], axis=3)
|
483 |
-
|
484 |
-
#out = concatenate([x, out], axis=3)
|
485 |
-
#out = tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=(1, 1), padding='same')(out)
|
486 |
-
#out = Conv2D(3, (3, 3), activation=activation_funtion, padding='same')(out)
|
487 |
-
#out = model7(out)
|
488 |
|
489 |
|
|
|
490 |
|
491 |
-
|
492 |
-
#out = model10_x(attention_weights)
|
493 |
-
#model11 = Conv2D(32, (3, 3), activation=activation_funtion, padding='same')(model11)
|
494 |
-
#model7 = Conv2D(32, (3, 3), activation=activation_funtion, padding='same')(model7)
|
495 |
-
#out = concatenate([model10_x(x), model10_x(augmented), model10_x(augmented_0)], axis=3)
|
496 |
-
#out = concatenate([ model7(x), model11(x),
|
497 |
-
# model7(augmented_0), model11(augmented_0),
|
498 |
-
# model7(augmented_1), model11(augmented_1),
|
499 |
-
# model7(augmented_2), model11(augmented_2),
|
500 |
-
# model7(augmented_3), model11(augmented_3),
|
501 |
-
# model7(augmented_4), model11(augmented_4),
|
502 |
-
# model7(augmented_5), model11(augmented_5)],axis=3)
|
503 |
-
|
504 |
-
#out = tf.keras.layers.PReLU()(out)
|
505 |
-
#out = Conv2D(64, (3, 3), activation=activation_funtion, padding='same')(out)
|
506 |
-
#out = BatchNormalization()(out)
|
507 |
-
#out = Dropout(0.2)(out)
|
508 |
-
|
509 |
-
#####out = hybrid_pool_layer((2,2))(out)
|
510 |
-
|
511 |
-
#a = tf.keras.layers.AveragePooling2D(padding='same')(out)
|
512 |
-
#a = Lambda(lambda xx : xx*alpha)(a)
|
513 |
-
#m = tf.keras.layers.MaxPooling2D(padding='same')(out)
|
514 |
-
#m = Lambda(lambda xx : xx*(1-alpha))(m)
|
515 |
-
#out = tf.keras.layers.Add()([a,m])
|
516 |
-
#out = tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=(1, 1), padding='same')(out)
|
517 |
-
|
518 |
-
#out = layers.add([model1.output, model2.output])
|
519 |
-
#out = layers.multiply([model1.output, model2.output])
|
520 |
-
##out = layers.add([model, encode.output])
|
521 |
-
##out = layers.multiply([model, encode.output])
|
522 |
-
|
523 |
-
#out = Conv2D(128, (3, 3), activation=activation_funtion, padding='same')(out)
|
524 |
-
#out = BatchNormalization()(out)
|
525 |
-
#out = Conv2D(64, (3, 3), activation=activation_funtion, padding='same')(out)
|
526 |
-
#out = SpikingActivation("relu")(out)
|
527 |
-
#out = BatchNormalization()(out)
|
528 |
-
#out = Dropout(0.2)(out)
|
529 |
-
#out = Conv2D(32, (3, 3), activation=activation_funtion, padding='same')(out)
|
530 |
-
#out = BatchNormalization()(out)
|
531 |
-
#out = Conv2D(64, (3, 3), activation=activation_funtion, padding='same')(out)
|
532 |
-
#out = BatchNormalization()(out)
|
533 |
-
#out = Dropout(0.2)(out)
|
534 |
-
#out = tf.keras.layers.PReLU()(out)
|
535 |
-
#out = Conv2D(64, (3, 3), activation=activation_funtion, padding='same')(out)
|
536 |
-
#out = BatchNormalization()(out)
|
537 |
-
#out = Dropout(0.2)(out)
|
538 |
-
#out = tf.keras.layers.PReLU()(out)
|
539 |
-
|
540 |
-
#out = concatenate([conv_out_jump, out], axis=3)
|
541 |
-
#out = Conv2D(256, (3, 3), activation=activation_funtion, padding='same')(out)
|
542 |
-
#out = BatchNormalization()(out)
|
543 |
-
#out = Dropout(0.2)(out)
|
544 |
-
|
545 |
-
#out = tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=(1, 1), padding='same')(out)
|
546 |
-
#out = UpSampling2D((2, 2))(out)
|
547 |
-
|
548 |
-
#out_list = []
|
549 |
-
#for i in range(1,23):
|
550 |
-
# outputs1 = Conv2D(n_classes-i, (1, 1), activation='softmax')(out)
|
551 |
-
# out_list.append(outputs1)
|
552 |
-
#outputs2 = Conv2D(n_classes-1, (1, 1), activation='softmax')(out)
|
553 |
-
#outputs3 = Conv2D(n_classes-2, (1, 1), activation='softmax')(out)
|
554 |
-
#outputs4 = Conv2D(n_classes-3, (1, 1), activation='softmax')(out)
|
555 |
-
#outputs5 = Conv2D(n_classes-4, (1, 1), activation='softmax')(out)
|
556 |
-
#outputs6 = Conv2D(n_classes-5, (1, 1), activation='softmax')(out)
|
557 |
-
#outputs7 = Conv2D(n_classes-6, (1, 1), activation='softmax')(out)
|
558 |
-
#outputs8 = Conv2D(n_classes-7, (1, 1), activation='softmax')(out)
|
559 |
-
#outputs9 = Conv2D(n_classes-8, (1, 1), activation='softmax')(out)
|
560 |
-
|
561 |
-
#out_list = [outputs1, outputs2, outputs3, outputs4, outputs5, outputs6, outputs7, outputs8, outputs9]
|
562 |
-
#outputs = Conv2D(n_classes, (1, 1), activation='softmax')(encode.output)
|
563 |
-
#outputs = concatenate(out_list, axis=3)
|
564 |
-
#outputs = tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=(1, 1), padding='same')(outputs)
|
565 |
outputs = Conv2D(n_classes, (1, 1), activation='softmax', padding='same')(out)
|
566 |
|
567 |
|
|
|
6 |
import tensorflow
|
7 |
import tensorflow as tf
|
8 |
from tensorflow.keras import backend as K
|
9 |
+
from tensorflow.keras.models import Model
|
10 |
+
from tensorflow.keras.optimizers import Adam
|
11 |
+
from tensorflow.keras.metrics import MeanIoU
|
12 |
+
from tensorflow.keras.utils import normalize, to_categorical
|
13 |
+
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D, concatenate, Conv2DTranspose, BatchNormalization, Dropout, Lambda
|
14 |
+
from tensorflow.keras import layers
|
15 |
|
16 |
size = 1024
|
17 |
pach_size = 256
|
|
|
357 |
|
358 |
encode = encoder_unet(inputs)
|
359 |
decode = decoder(encode.output, inputs)
|
360 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
outputs = decode.output
|
362 |
#outputs = Conv2D(n_classes, (1, 1), activation='softmax', padding='same', kernel_initializer='he_normal')(decode.output)
|
363 |
#outputs = tf.reshape(encode_2.output[0], [None, 16, 16, 256])
|
|
|
378 |
|
379 |
def unet_enssemble(n_classes=2, height=64, width=64, channels=3, metrics = ['accuracy']):
|
380 |
x = Input((height, width, channels))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
|
382 |
+
model10 = unet_2( n_classes=n_classes, height = height, width = width, channels = 3)
|
383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
|
385 |
|
386 |
+
out = model10(x)
|
387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
outputs = Conv2D(n_classes, (1, 1), activation='softmax', padding='same')(out)
|
389 |
|
390 |
|