Esempio n. 1
0
            open(options['file_arch'], 'w').write(json_string)
            model.save_weights(options['file_weight'])

        save(self.generator, "generator")
        save(self.discriminator, "discriminator")


if __name__ == '__main__':
    cgan = CGAN()
    
    #cgan.discriminator.load_weights("C:/Users/ZhenjuYin/Documents/Python Scripts/emotic/class/cgan/discriminatornew_weights.h5")
    #cgan.generator.load_weights("C:/Users/ZhenjuYin/Documents/Python Scripts/emotic/class/cgan/generatornew_weights.h5")
    cgan.classifier.load_weights("C:/Users/ZhenjuYin/Documents/Python Scripts/emotic/class/saved/model4_weights.h5")
    cgan.train(epochs=500, batch_size=16, sample_interval=20)

    data = np.load('C:/Users/ZhenjuYin/Documents/Python Scripts/emotic/test_image_data.npy',allow_pickle=True)
    image = (data[0:1].astype(np.float32)- 127.5) / 127.5
    f = Model(inputs=cgan.classifier.input,outputs=cgan.classifier.get_layer('seq').get_layer('m').output)(image)
    with tf.Session() as sess:
        f = f.eval()
        f = 0.5*f+0.5
        r, c = 4,4
        fig, axs = plt.subplots(r, c)
        cnt = 0
        for i in range(r):
            for j in range(c):
                axs[i,j].imshow(f[0,:,:,cnt])
                axs[i,j].axis('off')
                cnt += 1
        fig.savefig("C:/Users/ZhenjuYin/Documents/Python Scripts/emotic/class/cgan/imagesnew/c.png" )
Esempio n. 2
0
x = x.unsqueeze(0)
x.shape

preds = model(x)

preds.flatten().argsort()[:5]

# lets look at the model
model

model.conv_head

model.conv_head.weight

# How do we freeze weights
model.eval()
for parameter in model.parameters():
    print(f'{parameter.shape}\t\t\t\t\tTrainable {parameter.requires_grad}')
model

# Change the number of output classes
model.classifier = torch.nn.Linear(1536, 5)

out = model(x)
out.shape
out

dir(model)

# Make the conv_stem kernel_size 1 and stride 1
model.conv_stem