コード例 #1
0
def build_model():
    '''Reconstruct a trined model from saved data.
    '''

    os.environ["CUDA_VISIBLE_DEVICES"] = "0"


    with open("models/2020-03-06-16-21-20/topology.txt", "r") as topology:
        num_filters = tuple(map(int, topology.readline()[1:-1].split(', ')))

    input_shape = (None, None, 3)
   
    model = Autoencoder(input_shape=input_shape, num_filters=num_filters)
    model = model.build()

    model.load_weights("models/2020-03-06-16-21-20/weights.h5")
    model.compile(optimizer="adam", loss="MSE", metrics=["accuracy"])

    return model
コード例 #2
0
    args = parser.parse_args()


    os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu


    with open(args.topology, "r") as topology:
        num_filters = tuple(map(int, topology.readline()[1:-1].split(', ')))
    
    files = glob.glob(os.path.join(args.file_dir, "*.png"))

    input_shape = (None, None, 3)
   
    # Reconstruct model from saved weights
    model = Autoencoder(input_shape=input_shape, num_filters=num_filters)
    model = model.build()
    print(model.summary())

    model.load_weights(args.weights)
    model.compile(optimizer="adam", loss="MSE", metrics=["accuracy"])

    # Generate time stamp for unique id of the result
    time_stamp = "{date:%Y-%m-%d-%H-%M-%S}".format(date=datetime.datetime.now())

    # Pass images to network
    for file, i in zip(files, range(len(files))):

        inp_img = cv2.imread(file) / 255
        inp_img = np.expand_dims(inp_img, axis=0)

        out_img = model.predict(inp_img)