简体   繁体   中英

I get wrong data form AutoEncoder tensorflow2.0 Data in chronological order

I made an Autoencoder model, and run a test

  • behavior In my image:
    • input: 7data * 88 width
    • output: 7data * 88 width
  • behavior real
    • input: 7data * 88 width
    • output: 7data * 88 * 88

how to fix it help me;;

environment: tensorflow2.0

code

import tensorflow as tf

from tensorflow.keras.layers import Dense, Flatten, Conv2D
from tensorflow.keras import Model

from matplotlib import pyplot as plt #プロット

# create model
width = 88
%matplotlib inline
class MyModel(Model):
    def __init__(self):
        super(MyModel, self).__init__()

        self.d1 = Dense(width, activation='tanh')
        self.d2 = Dense(width/8, activation='tanh')
        self.d3 = Dense(width, activation='tanh')

    def call(self, x):   
        x = self.d1(x)
        x = self.d2(x)
        return self.d3(x)
model3 = MyModel()

# create dataset (TOO easy)
import numpy as np
def f(x):    
    x = x/width
    return x

arange = np.arange(0,width,1)
if 'test' in locals():
    del test
for j in range(7):

    x = []
    for i in range(len(arange)):
        x.append(f(arange[i]))

    if 'test' in locals():
        test = np.vstack([test,x])
    else:
        test = x
    plt.plot(x)

test= test[..., tf.newaxis]

# run test
print(model3(test).numpy().shape)

answer

output shape: (7, 88, 88)

changing data type numpy to tf.tensor make it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM