Spaces:
Runtime error
Runtime error
Update app.py
Browse files9 unmodified lines1011121314159 unmodified linesSTYLE_LAYERS = [...] # same layers as in your notebookCONTENT_LAYER = [...] # e.g. [('block5_conv4', 1)]def preprocess(img):img = Image.fromarray(img).resize((256, 256))arr = np.expand_dims(np.array(img) / 255.0, axis=0).astype(np.float32)9 unmodified lines1011121314151617181920212223242526272829303132333435363738394041429 unmodified linesSTYLE_LAYERS = [...] # same layers as in your notebookCONTENT_LAYER = [...] # e.g. [('block5_conv4', 1)]def gram_matrix(A):"""Compute Gram matrix for style representation."""A = tf.transpose(A, (0, 3, 1, 2)) # (batch, channels, height, width)features = tf.reshape(A, (A.shape[0], A.shape[1], -1))gram = tf.matmul(features, features, transpose_b=True)return gram / tf.cast(tf.shape(features)[-1], tf.float32)def compute_content_cost(a_C, a_G):"""Content cost between content and generated image features."""return tf.reduce_mean(tf.square(a_C - a_G))def compute_style_cost(a_S, a_G):"""Style cost using Gram matrices."""J_style = 0for s, g in zip(a_S, a_G):J_style += tf.reduce_mean(tf.square(gram_matrix(s) - gram_matrix(g)))return J_style / len(a_S)def total_cost(J_content, J_style, alpha=10, beta=40):"""Weighted sum of content + style."""return alpha * J_content + beta * J_styledef clip_0_1(img):"""Keep pixel values in [0,1]."""return tf.clip_by_value(img, 0.0, 1.0)def preprocess(img):img = Image.fromarray(img).resize((256, 256))arr = np.expand_dims(np.array(img) / 255.0, axis=0).astype(np.float32)
app.py+27