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
| import math, re, os import tensorflow as tf import numpy as np import matplotlib.pyplot as plt from sklearn.metrics import f1_score, precision_score, recall_score, confusion_matrix
print(tf.__version__) AUTO = tf.data.experimental.AUTOTUNE
try: tpu = tf.distribute.cluster_resolver.TPUClusterResolver.connect() strategy = tf.distribute.TPUStrategy(tpu) except ValueError: strategy = tf.distribute.MirroredStrategy() strategy = tf.distribute.get_strategy() strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy()
print("加速器数目:", strategy.num_replicas_in_sync)
IMG_SIZE = [512, 512]
EPOCHS = 12 BATCH_SIZE = 16 * strategy.num_replicas_in_sync DATA_DIR = r'flowers' DATA_SIZE_SELECT = { 192: DATA_DIR + '/tfrecords-jpeg-192x192', 224: DATA_DIR + '/tfrecords-jpeg-224x224', 331: DATA_DIR + '/tfrecords-jpeg-331x331', 512: DATA_DIR + '/tfrecords-jpeg-512x512', }
DATA_SELECT = DATA_SIZE_SELECT[IMG_SIZE[0]] TRAINING_FILENAMES = tf.io.gfile.glob(DATA_SELECT + '/train/*.tfrec') VALID_FILENAMES = tf.io.gfile.glob(DATA_SELECT + '/val/*.tfrec') TEST_FILENAMES = tf.io.gfile.glob(DATA_SELECT + '/test/*.tfrec')
IMG_SIZE = [512, 512]
EPOCHS = 12 BATCH_SIZE = 16 * strategy.num_replicas_in_sync DATA_DIR = r'/content/work/flowers' DATA_SIZE_SELECT = { 192: DATA_DIR + '/tfrecords-jpeg-192x192', 224: DATA_DIR + '/tfrecords-jpeg-224x224', 331: DATA_DIR + '/tfrecords-jpeg-331x331', 512: DATA_DIR + '/tfrecords-jpeg-512x512', }
DATA_SELECT = DATA_SIZE_SELECT[IMG_SIZE[0]] TRAINING_FILENAMES = tf.io.gfile.glob(DATA_SELECT + '/train/*.tfrec') VALID_FILENAMES = tf.io.gfile.glob(DATA_SELECT + '/val/*.tfrec') TEST_FILENAMES = tf.io.gfile.glob(DATA_SELECT + '/test/*.tfrec')
CLASSES = ['pink primrose', 'hard-leaved pocket orchid', 'canterbury bells', 'sweet pea', 'wild geranium', 'tiger lily', 'moon orchid', 'bird of paradise', 'monkshood', 'globe thistle', 'snapdragon', "colt's foot", 'king protea', 'spear thistle', 'yellow iris', 'globe-flower', 'purple coneflower', 'peruvian lily', 'balloon flower', 'giant white arum lily', 'fire lily', 'pincushion flower', 'fritillary', 'red ginger', 'grape hyacinth', 'corn poppy', 'prince of wales feathers', 'stemless gentian', 'artichoke', 'sweet william', 'carnation', 'garden phlox', 'love in the mist', 'cosmos', 'alpine sea holly', 'ruby-lipped cattleya', 'cape flower', 'great masterwort', 'siam tulip', 'lenten rose', 'barberton daisy', 'daffodil', 'sword lily', 'poinsettia', 'bolero deep blue', 'wallflower', 'marigold', 'buttercup', 'daisy', 'common dandelion', 'petunia', 'wild pansy', 'primula', 'sunflower', 'lilac hibiscus', 'bishop of llandaff', 'gaura', 'geranium', 'orange dahlia', 'pink-yellow dahlia', 'cautleya spicata', 'japanese anemone', 'black-eyed susan', 'silverbush', 'californian poppy', 'osteospermum', 'spring crocus', 'iris', 'windflower', 'tree poppy', 'gazania', 'azalea', 'water lily', 'rose', 'thorn apple', 'morning glory', 'passion flower', 'lotus', 'toad lily', 'anthurium', 'frangipani', 'clematis', 'hibiscus', 'columbine', 'desert-rose', 'tree mallow', 'magnolia', 'cyclamen ', 'watercress', 'canna lily', 'hippeastrum ', 'bee balm', 'pink quill', 'foxglove', 'bougainvillea', 'camellia', 'mallow', 'mexican petunia', 'bromelia', 'blanket flower', 'trumpet creeper', 'blackberry lily', 'common tulip', 'wild rose']
|