我不知道为什么,但我开始在 Vercel 上收到这些错误,但在 LocalHost 上没有问题,即使执行 import os
import numpy as np
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.datasets import fashion_mnist
from tensorflow.keras.layers import *
from tensorflow.keras.activations import *
from tensorflow.keras.models import *
from tensorflow.keras.optimizers import *
from tensorflow.keras.initializers import *
# load and preprocess dataset
# Dataset
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
# Cast to np.float32
x_train = x_train.astype(np.float32)
y_train = y_train.astype(np.float32)
x_test = x_test.astype(np.float32)
y_test = y_test.astype(np.float32)
# Dataset variables
train_size = x_train.shape[0]
test_size = x_test.shape[0]
num_timesteps = 784
num_features = 10
num_classes = 10
img_shape = (28, 28, 1,1)
# Compute the categorical classes
y_train = to_categorical(y_train, num_classes=10)
y_test = to_categorical(y_test, num_classes=10)
# Reshape the input data
#x_train = x_train.reshape(train_size, num_timesteps, num_features, 1)
#x_test = x_test.reshape(test_size, num_timesteps, num_features,1)
x_train = np.expand_dims(x_train, axis=-1)
x_test = np.expand_dims(x_test, axis=-1)
# Model params
lr = 0.001
optimizer = Adam(lr=lr)
epochs = 10
batch_size = 256
units = 50
return_sequences = True
print(img_shape)
# Define the DNN
model = Sequential()
# first CONV => RELU => CONV => RELU => POOL layer set
model.add(TimeDistributed(Conv2D(filters=32, kernel_size=3, padding="same", input_shape=img_shape)))
model.add(TimeDistributed(Activation("relu")))
model.add(TimeDistributed(BatchNormalization()))
model.add(TimeDistributed(Conv2D(filters=32, kernel_size=3, padding="same")))
model.add(TimeDistributed(Activation("relu")))
model.add(TimeDistributed(BatchNormalization()))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
model.add(TimeDistributed(Dropout(0.25)))
# second CONV => RELU => CONV => RELU => POOL layer set
model.add(TimeDistributed(Conv2D(filters=64, kernel_size=3, padding="same")))
model.add(TimeDistributed(Activation("relu")))
model.add(TimeDistributed(BatchNormalization()))
model.add(TimeDistributed(Conv2D(filters=64, kernel_size=3, padding="same")))
model.add(TimeDistributed(Activation("relu")))
model.add(TimeDistributed(BatchNormalization()))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
model.add(TimeDistributed(Dropout(0.25)))
# LSTM => RELU => FC => SOFTMAX (output)
model.add(LSTM(units=units, return_sequences=return_sequences))
model.add(Activation("relu"))
model.add(Dense(units=num_classes))
model.add(Activation("softmax"))
#model.summary()
# Compile and train (fit) the model, afterwards evaluate the model
model.compile(
loss="categorical_crossentropy",
optimizer=optimizer,
metrics=["accuracy"])
model.fit(
x=x_train,
y=y_train,
epochs=epochs,
batch_size=batch_size,
validation_data=[x_test, y_test])
score = model.evaluate(
x_test,
y_test,
verbose=0)
print("Score: ", score)
我已经确定我在 Next.js 中使用 CORS
还有我的api代码
yarn build && yarn start
我一评论
import bcrypt from 'bcrypt'
import { NextApiRequest, NextApiResponse } from 'next'
import { connectPrisma } from 'utils/connectPrisma'
export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
const { email, password } = req.body
if (!email || !password) return res.status(422).json({ error: 'Please complete all fields' })
try {
const { client } = await connectPrisma()
const user = await client.user.findFirst({ where: { email } })
if (user) {
return res.status(422).json({ error: `User already exists with that email` })
}
const hashedPassword = await bcrypt.hash(password, 8)
await client.user.create({ data: { email: email, password: hashedPassword } })
res.status(201).json({ message: 'Success test' })
} catch {
res.status(500).json({ error: 'Unable to insert user' })
}
return
}
return res.status(500).json({ error: 'Invalid request' })
}
我可以做 POST 请求